VirtualSCADA  1.0
VirtualSCADA Senior Design Project
compiled.php
Go to the documentation of this file.
1 <?php
3 
4 use Closure;
5 interface Container
6 {
7  public function bound($abstract);
8  public function alias($abstract, $alias);
9  public function tag($abstracts, $tags);
10  public function tagged($tag);
11  public function bind($abstract, $concrete = null, $shared = false);
12  public function bindIf($abstract, $concrete = null, $shared = false);
13  public function singleton($abstract, $concrete = null);
14  public function extend($abstract, Closure $closure);
15  public function instance($abstract, $instance);
16  public function when($concrete);
17  public function make($abstract, $parameters = array());
18  public function call($callback, array $parameters = array(), $defaultMethod = null);
19  public function resolved($abstract);
20  public function resolving($abstract, Closure $callback = null);
21  public function afterResolving($abstract, Closure $callback = null);
22 }
24 
26 {
27  public function needs($abstract);
28  public function give($implementation);
29 }
31 
33 interface Application extends Container
34 {
35  public function version();
36  public function basePath();
37  public function environment();
38  public function isDownForMaintenance();
39  public function registerConfiguredProviders();
40  public function register($provider, $options = array(), $force = false);
41  public function registerDeferredProvider($provider, $service = null);
42  public function boot();
43  public function booting($callback);
44  public function booted($callback);
45 }
47 
48 use Closure;
49 use ArrayAccess;
50 interface Dispatcher
51 {
52  public function dispatchFromArray($command, array $array);
53  public function dispatchFrom($command, ArrayAccess $source, array $extras = array());
54  public function dispatch($command, Closure $afterResolving = null);
55  public function dispatchNow($command, Closure $afterResolving = null);
56  public function pipeThrough(array $pipes);
57 }
58 namespace Illuminate\Contracts\Bus;
59 
60 interface QueueingDispatcher extends Dispatcher
61 {
62  public function dispatchToQueue($command);
63 }
64 namespace Illuminate\Contracts\Bus;
65 
66 use Closure;
67 interface HandlerResolver
68 {
69  public function resolveHandler($command);
70  public function getHandlerClass($command);
71  public function getHandlerMethod($command);
72  public function maps(array $commands);
73  public function mapUsing(Closure $mapper);
74 }
76 
77 use Closure;
78 interface Pipeline
79 {
80  public function send($traveler);
81  public function through($stops);
82  public function via($method);
83  public function then(Closure $destination);
84 }
86 
87 interface Renderable
88 {
89  public function render();
90 }
92 
93 interface Log
94 {
95  public function alert($message, array $context = array());
96  public function critical($message, array $context = array());
97  public function error($message, array $context = array());
98  public function warning($message, array $context = array());
99  public function notice($message, array $context = array());
100  public function info($message, array $context = array());
101  public function debug($message, array $context = array());
102  public function log($level, $message, array $context = array());
103  public function useFiles($path, $level = 'debug');
104  public function useDailyFiles($path, $days = 0, $level = 'debug');
105 }
107 
108 interface Repository
109 {
110  public function has($key);
111  public function get($key, $default = null);
112  public function set($key, $value = null);
113  public function prepend($key, $value);
114  public function push($key, $value);
115 }
117 
118 interface Dispatcher
119 {
120  public function listen($events, $listener, $priority = 0);
121  public function hasListeners($eventName);
122  public function until($event, $payload = array());
123  public function fire($event, $payload = array(), $halt = false);
124  public function firing();
125  public function forget($event);
126  public function forgetPushed();
127 }
129 
130 interface Arrayable
131 {
132  public function toArray();
133 }
135 
136 interface Jsonable
137 {
138  public function toJson($options = 0);
139 }
141 
142 interface Factory
143 {
144  public function make($name, $value, $minutes = 0, $path = null, $domain = null, $secure = false, $httpOnly = true);
145  public function forever($name, $value, $path = null, $domain = null, $secure = false, $httpOnly = true);
146  public function forget($name, $path = null, $domain = null);
147 }
149 
150 interface QueueingFactory extends Factory
151 {
152  public function queue();
153  public function unqueue($name);
154  public function getQueuedCookies();
155 }
157 
158 interface Encrypter
159 {
160  public function encrypt($value);
161  public function decrypt($payload);
162  public function setMode($mode);
163  public function setCipher($cipher);
164 }
166 
168 {
169  public function getQueueableId();
170 }
172 
173 use Closure;
174 interface Registrar
175 {
176  public function get($uri, $action);
177  public function post($uri, $action);
178  public function put($uri, $action);
179  public function delete($uri, $action);
180  public function patch($uri, $action);
181  public function options($uri, $action);
182  public function match($methods, $uri, $action);
183  public function resource($name, $controller, array $options = array());
184  public function group(array $attributes, Closure $callback);
185  public function before($callback);
186  public function after($callback);
187  public function filter($name, $callback);
188 }
190 
192 {
193  public function make($content = '', $status = 200, array $headers = array());
194  public function view($view, $data = array(), $status = 200, array $headers = array());
195  public function json($data = array(), $status = 200, array $headers = array(), $options = 0);
196  public function jsonp($callback, $data = array(), $status = 200, array $headers = array(), $options = 0);
197  public function stream($callback, $status = 200, array $headers = array());
198  public function download($file, $name = null, array $headers = array(), $disposition = 'attachment');
199  public function redirectTo($path, $status = 302, $headers = array(), $secure = null);
200  public function redirectToRoute($route, $parameters = array(), $status = 302, $headers = array());
201  public function redirectToAction($action, $parameters = array(), $status = 302, $headers = array());
202  public function redirectGuest($path, $status = 302, $headers = array(), $secure = null);
203  public function redirectToIntended($default = '/', $status = 302, $headers = array(), $secure = null);
204 }
206 
207 interface UrlGenerator
208 {
209  public function to($path, $extra = array(), $secure = null);
210  public function secure($path, $parameters = array());
211  public function asset($path, $secure = null);
212  public function route($name, $parameters = array(), $absolute = true);
213  public function action($action, $parameters = array(), $absolute = true);
214  public function setRootControllerNamespace($rootNamespace);
215 }
217 
218 interface UrlRoutable
219 {
220  public function getRouteKey();
221  public function getRouteKeyName();
222 }
224 
225 use Closure;
226 interface Middleware
227 {
228  public function handle($request, Closure $next);
229 }
231 
233 {
234  public function terminate($request, $response);
235 }
237 
239 {
240  public function validate();
241 }
243 
244 interface Factory
245 {
246  public function exists($view);
247  public function file($path, $data = array(), $mergeData = array());
248  public function make($view, $data = array(), $mergeData = array());
249  public function share($key, $value = null);
250  public function composer($views, $callback, $priority = null);
251  public function creator($views, $callback);
252  public function addNamespace($namespace, $hints);
253 }
255 
257 {
258  public function getMessageBag();
259 }
261 
262 interface MessageBag
263 {
264  public function keys();
265  public function add($key, $message);
266  public function merge($messages);
267  public function has($key = null);
268  public function first($key = null, $format = null);
269  public function get($key, $format = null);
270  public function all($format = null);
271  public function getFormat();
272  public function setFormat($format = ':message');
273  public function isEmpty();
274  public function count();
275  public function toArray();
276 }
277 namespace Illuminate\Contracts\View;
278 
280 interface View extends Renderable
281 {
282  public function name();
283  public function with($key, $value = null);
284 }
286 
287 interface Kernel
288 {
289  public function bootstrap();
290  public function handle($request);
291  public function terminate($request, $response);
292  public function getApplication();
293 }
295 
296 interface Guard
297 {
298  public function check();
299  public function guest();
300  public function user();
301  public function once(array $credentials = array());
302  public function attempt(array $credentials = array(), $remember = false, $login = true);
303  public function basic($field = 'email');
304  public function onceBasic($field = 'email');
305  public function validate(array $credentials = array());
306  public function login(Authenticatable $user, $remember = false);
307  public function loginUsingId($id, $remember = false);
308  public function viaRemember();
309  public function logout();
310 }
312 
313 interface Hasher
314 {
315  public function make($value, array $options = array());
316  public function check($value, $hashedValue, array $options = array());
317  public function needsRehash($hashedValue, array $options = array());
318 }
319 namespace Illuminate\Auth;
320 
322 class AuthManager extends Manager
323 {
324  protected function createDriver($driver)
325  {
326  $guard = parent::createDriver($driver);
327  $guard->setCookieJar($this->app['cookie']);
328  $guard->setDispatcher($this->app['events']);
329  return $guard->setRequest($this->app->refresh('request', $guard, 'setRequest'));
330  }
331  protected function callCustomCreator($driver)
332  {
333  $custom = parent::callCustomCreator($driver);
334  if ($custom instanceof Guard) {
335  return $custom;
336  }
337  return new Guard($custom, $this->app['session.store']);
338  }
339  public function createDatabaseDriver()
340  {
341  $provider = $this->createDatabaseProvider();
342  return new Guard($provider, $this->app['session.store']);
343  }
344  protected function createDatabaseProvider()
345  {
346  $connection = $this->app['db']->connection();
347  $table = $this->app['config']['auth.table'];
348  return new DatabaseUserProvider($connection, $this->app['hash'], $table);
349  }
350  public function createEloquentDriver()
351  {
352  $provider = $this->createEloquentProvider();
353  return new Guard($provider, $this->app['session.store']);
354  }
355  protected function createEloquentProvider()
356  {
357  $model = $this->app['config']['auth.model'];
358  return new EloquentUserProvider($this->app['hash'], $model);
359  }
360  public function getDefaultDriver()
361  {
362  return $this->app['config']['auth.driver'];
363  }
364  public function setDefaultDriver($name)
365  {
366  $this->app['config']['auth.driver'] = $name;
367  }
368 }
369 namespace Illuminate\Auth;
370 
371 use RuntimeException;
380 class Guard implements GuardContract
381 {
382  protected $user;
383  protected $lastAttempted;
384  protected $viaRemember = false;
385  protected $provider;
386  protected $session;
387  protected $cookie;
388  protected $request;
389  protected $events;
390  protected $loggedOut = false;
391  protected $tokenRetrievalAttempted = false;
392  public function __construct(UserProvider $provider, SessionInterface $session, Request $request = null)
393  {
394  $this->session = $session;
395  $this->request = $request;
396  $this->provider = $provider;
397  }
398  public function check()
399  {
400  return !is_null($this->user());
401  }
402  public function guest()
403  {
404  return !$this->check();
405  }
406  public function user()
407  {
408  if ($this->loggedOut) {
409  return;
410  }
411  if (!is_null($this->user)) {
412  return $this->user;
413  }
414  $id = $this->session->get($this->getName());
415  $user = null;
416  if (!is_null($id)) {
417  $user = $this->provider->retrieveById($id);
418  }
419  $recaller = $this->getRecaller();
420  if (is_null($user) && !is_null($recaller)) {
421  $user = $this->getUserByRecaller($recaller);
422  if ($user) {
423  $this->updateSession($user->getAuthIdentifier());
424  $this->fireLoginEvent($user, true);
425  }
426  }
427  return $this->user = $user;
428  }
429  public function id()
430  {
431  if ($this->loggedOut) {
432  return;
433  }
434  $id = $this->session->get($this->getName(), $this->getRecallerId());
435  if (is_null($id) && $this->user()) {
436  $id = $this->user()->getAuthIdentifier();
437  }
438  return $id;
439  }
440  protected function getUserByRecaller($recaller)
441  {
442  if ($this->validRecaller($recaller) && !$this->tokenRetrievalAttempted) {
443  $this->tokenRetrievalAttempted = true;
444  list($id, $token) = explode('|', $recaller, 2);
445  $this->viaRemember = !is_null($user = $this->provider->retrieveByToken($id, $token));
446  return $user;
447  }
448  }
449  protected function getRecaller()
450  {
451  return $this->request->cookies->get($this->getRecallerName());
452  }
453  protected function getRecallerId()
454  {
455  if ($this->validRecaller($recaller = $this->getRecaller())) {
456  return head(explode('|', $recaller));
457  }
458  }
459  protected function validRecaller($recaller)
460  {
461  if (!is_string($recaller) || !str_contains($recaller, '|')) {
462  return false;
463  }
464  $segments = explode('|', $recaller);
465  return count($segments) == 2 && trim($segments[0]) !== '' && trim($segments[1]) !== '';
466  }
467  public function once(array $credentials = array())
468  {
469  if ($this->validate($credentials)) {
470  $this->setUser($this->lastAttempted);
471  return true;
472  }
473  return false;
474  }
475  public function validate(array $credentials = array())
476  {
477  return $this->attempt($credentials, false, false);
478  }
479  public function basic($field = 'email')
480  {
481  if ($this->check()) {
482  return;
483  }
484  if ($this->attemptBasic($this->getRequest(), $field)) {
485  return;
486  }
487  return $this->getBasicResponse();
488  }
489  public function onceBasic($field = 'email')
490  {
491  if (!$this->once($this->getBasicCredentials($this->getRequest(), $field))) {
492  return $this->getBasicResponse();
493  }
494  }
495  protected function attemptBasic(Request $request, $field)
496  {
497  if (!$request->getUser()) {
498  return false;
499  }
500  return $this->attempt($this->getBasicCredentials($request, $field));
501  }
502  protected function getBasicCredentials(Request $request, $field)
503  {
504  return array($field => $request->getUser(), 'password' => $request->getPassword());
505  }
506  protected function getBasicResponse()
507  {
508  $headers = array('WWW-Authenticate' => 'Basic');
509  return new Response('Invalid credentials.', 401, $headers);
510  }
511  public function attempt(array $credentials = array(), $remember = false, $login = true)
512  {
513  $this->fireAttemptEvent($credentials, $remember, $login);
514  $this->lastAttempted = $user = $this->provider->retrieveByCredentials($credentials);
515  if ($this->hasValidCredentials($user, $credentials)) {
516  if ($login) {
517  $this->login($user, $remember);
518  }
519  return true;
520  }
521  return false;
522  }
523  protected function hasValidCredentials($user, $credentials)
524  {
525  return !is_null($user) && $this->provider->validateCredentials($user, $credentials);
526  }
527  protected function fireAttemptEvent(array $credentials, $remember, $login)
528  {
529  if ($this->events) {
530  $payload = array($credentials, $remember, $login);
531  $this->events->fire('auth.attempt', $payload);
532  }
533  }
534  public function attempting($callback)
535  {
536  if ($this->events) {
537  $this->events->listen('auth.attempt', $callback);
538  }
539  }
540  public function login(UserContract $user, $remember = false)
541  {
542  $this->updateSession($user->getAuthIdentifier());
543  if ($remember) {
544  $this->createRememberTokenIfDoesntExist($user);
545  $this->queueRecallerCookie($user);
546  }
547  $this->fireLoginEvent($user, $remember);
548  $this->setUser($user);
549  }
550  protected function fireLoginEvent($user, $remember = false)
551  {
552  if (isset($this->events)) {
553  $this->events->fire('auth.login', array($user, $remember));
554  }
555  }
556  protected function updateSession($id)
557  {
558  $this->session->set($this->getName(), $id);
559  $this->session->migrate(true);
560  }
561  public function loginUsingId($id, $remember = false)
562  {
563  $this->session->set($this->getName(), $id);
564  $this->login($user = $this->provider->retrieveById($id), $remember);
565  return $user;
566  }
567  public function onceUsingId($id)
568  {
569  $this->setUser($this->provider->retrieveById($id));
570  return $this->user instanceof UserContract;
571  }
572  protected function queueRecallerCookie(UserContract $user)
573  {
574  $value = $user->getAuthIdentifier() . '|' . $user->getRememberToken();
575  $this->getCookieJar()->queue($this->createRecaller($value));
576  }
577  protected function createRecaller($value)
578  {
579  return $this->getCookieJar()->forever($this->getRecallerName(), $value);
580  }
581  public function logout()
582  {
583  $user = $this->user();
584  $this->clearUserDataFromStorage();
585  if (!is_null($this->user)) {
586  $this->refreshRememberToken($user);
587  }
588  if (isset($this->events)) {
589  $this->events->fire('auth.logout', array($user));
590  }
591  $this->user = null;
592  $this->loggedOut = true;
593  }
594  protected function clearUserDataFromStorage()
595  {
596  $this->session->remove($this->getName());
597  $recaller = $this->getRecallerName();
598  $this->getCookieJar()->queue($this->getCookieJar()->forget($recaller));
599  }
600  protected function refreshRememberToken(UserContract $user)
601  {
602  $user->setRememberToken($token = str_random(60));
603  $this->provider->updateRememberToken($user, $token);
604  }
605  protected function createRememberTokenIfDoesntExist(UserContract $user)
606  {
607  $rememberToken = $user->getRememberToken();
608  if (empty($rememberToken)) {
609  $this->refreshRememberToken($user);
610  }
611  }
612  public function getCookieJar()
613  {
614  if (!isset($this->cookie)) {
615  throw new RuntimeException('Cookie jar has not been set.');
616  }
617  return $this->cookie;
618  }
619  public function setCookieJar(CookieJar $cookie)
620  {
621  $this->cookie = $cookie;
622  }
623  public function getDispatcher()
624  {
625  return $this->events;
626  }
627  public function setDispatcher(Dispatcher $events)
628  {
629  $this->events = $events;
630  }
631  public function getSession()
632  {
633  return $this->session;
634  }
635  public function getProvider()
636  {
637  return $this->provider;
638  }
639  public function setProvider(UserProvider $provider)
640  {
641  $this->provider = $provider;
642  }
643  public function getUser()
644  {
645  return $this->user;
646  }
647  public function setUser(UserContract $user)
648  {
649  $this->user = $user;
650  $this->loggedOut = false;
651  }
652  public function getRequest()
653  {
654  return $this->request ?: Request::createFromGlobals();
655  }
656  public function setRequest(Request $request)
657  {
658  $this->request = $request;
659  return $this;
660  }
661  public function getLastAttempted()
662  {
663  return $this->lastAttempted;
664  }
665  public function getName()
666  {
667  return 'login_' . md5(get_class($this));
668  }
669  public function getRecallerName()
670  {
671  return 'remember_' . md5(get_class($this));
672  }
673  public function viaRemember()
674  {
675  return $this->viaRemember;
676  }
677 }
678 namespace Illuminate\Contracts\Auth;
679 
680 interface UserProvider
681 {
682  public function retrieveById($identifier);
683  public function retrieveByToken($identifier, $token);
684  public function updateRememberToken(Authenticatable $user, $token);
685  public function retrieveByCredentials(array $credentials);
686  public function validateCredentials(Authenticatable $user, array $credentials);
687 }
688 namespace Illuminate\Auth;
689 
691 use Illuminate\Contracts\Hashing\Hasher as HasherContract;
694 {
695  protected $hasher;
696  protected $model;
697  public function __construct(HasherContract $hasher, $model)
698  {
699  $this->model = $model;
700  $this->hasher = $hasher;
701  }
702  public function retrieveById($identifier)
703  {
704  return $this->createModel()->newQuery()->find($identifier);
705  }
706  public function retrieveByToken($identifier, $token)
707  {
708  $model = $this->createModel();
709  return $model->newQuery()->where($model->getKeyName(), $identifier)->where($model->getRememberTokenName(), $token)->first();
710  }
711  public function updateRememberToken(UserContract $user, $token)
712  {
713  $user->setRememberToken($token);
714  $user->save();
715  }
716  public function retrieveByCredentials(array $credentials)
717  {
718  $query = $this->createModel()->newQuery();
719  foreach ($credentials as $key => $value) {
720  if (!str_contains($key, 'password')) {
721  $query->where($key, $value);
722  }
723  }
724  return $query->first();
725  }
726  public function validateCredentials(UserContract $user, array $credentials)
727  {
728  $plain = $credentials['password'];
729  return $this->hasher->check($plain, $user->getAuthPassword());
730  }
731  public function createModel()
732  {
733  $class = '\\' . ltrim($this->model, '\\');
734  return new $class();
735  }
736 }
738 
739 use Closure;
740 use ArrayAccess;
741 use ReflectionClass;
742 use ReflectionMethod;
747 class Container implements ArrayAccess, ContainerContract
748 {
749  protected static $instance;
750  protected $resolved = array();
751  protected $bindings = array();
752  protected $instances = array();
753  protected $aliases = array();
754  protected $extenders = array();
755  protected $tags = array();
756  protected $buildStack = array();
757  public $contextual = array();
758  protected $reboundCallbacks = array();
759  protected $globalResolvingCallbacks = array();
760  protected $globalAfterResolvingCallbacks = array();
761  protected $resolvingCallbacks = array();
762  protected $afterResolvingCallbacks = array();
763  public function when($concrete)
764  {
765  return new ContextualBindingBuilder($this, $concrete);
766  }
767  protected function resolvable($abstract)
768  {
769  return $this->bound($abstract);
770  }
771  public function bound($abstract)
772  {
773  return isset($this->bindings[$abstract]) || isset($this->instances[$abstract]) || $this->isAlias($abstract);
774  }
775  public function resolved($abstract)
776  {
777  return isset($this->resolved[$abstract]) || isset($this->instances[$abstract]);
778  }
779  public function isAlias($name)
780  {
781  return isset($this->aliases[$name]);
782  }
783  public function bind($abstract, $concrete = null, $shared = false)
784  {
785  if (is_array($abstract)) {
786  list($abstract, $alias) = $this->extractAlias($abstract);
787  $this->alias($abstract, $alias);
788  }
789  $this->dropStaleInstances($abstract);
790  if (is_null($concrete)) {
791  $concrete = $abstract;
792  }
793  if (!$concrete instanceof Closure) {
794  $concrete = $this->getClosure($abstract, $concrete);
795  }
796  $this->bindings[$abstract] = compact('concrete', 'shared');
797  if ($this->resolved($abstract)) {
798  $this->rebound($abstract);
799  }
800  }
801  protected function getClosure($abstract, $concrete)
802  {
803  return function ($c, $parameters = array()) use($abstract, $concrete) {
804  $method = $abstract == $concrete ? 'build' : 'make';
805  return $c->{$method}($concrete, $parameters);
806  };
807  }
808  public function addContextualBinding($concrete, $abstract, $implementation)
809  {
810  $this->contextual[$concrete][$abstract] = $implementation;
811  }
812  public function bindIf($abstract, $concrete = null, $shared = false)
813  {
814  if (!$this->bound($abstract)) {
815  $this->bind($abstract, $concrete, $shared);
816  }
817  }
818  public function singleton($abstract, $concrete = null)
819  {
820  $this->bind($abstract, $concrete, true);
821  }
822  public function share(Closure $closure)
823  {
824  return function ($container) use($closure) {
825  static $object;
826  if (is_null($object)) {
827  $object = $closure($container);
828  }
829  return $object;
830  };
831  }
832  public function bindShared($abstract, Closure $closure)
833  {
834  $this->bind($abstract, $this->share($closure), true);
835  }
836  public function extend($abstract, Closure $closure)
837  {
838  if (isset($this->instances[$abstract])) {
839  $this->instances[$abstract] = $closure($this->instances[$abstract], $this);
840  $this->rebound($abstract);
841  } else {
842  $this->extenders[$abstract][] = $closure;
843  }
844  }
845  public function instance($abstract, $instance)
846  {
847  if (is_array($abstract)) {
848  list($abstract, $alias) = $this->extractAlias($abstract);
849  $this->alias($abstract, $alias);
850  }
851  unset($this->aliases[$abstract]);
852  $bound = $this->bound($abstract);
853  $this->instances[$abstract] = $instance;
854  if ($bound) {
855  $this->rebound($abstract);
856  }
857  }
858  public function tag($abstracts, $tags)
859  {
860  $tags = is_array($tags) ? $tags : array_slice(func_get_args(), 1);
861  foreach ($tags as $tag) {
862  if (!isset($this->tags[$tag])) {
863  $this->tags[$tag] = array();
864  }
865  foreach ((array) $abstracts as $abstract) {
866  $this->tags[$tag][] = $abstract;
867  }
868  }
869  }
870  public function tagged($tag)
871  {
872  $results = array();
873  foreach ($this->tags[$tag] as $abstract) {
874  $results[] = $this->make($abstract);
875  }
876  return $results;
877  }
878  public function alias($abstract, $alias)
879  {
880  $this->aliases[$alias] = $abstract;
881  }
882  protected function extractAlias(array $definition)
883  {
884  return array(key($definition), current($definition));
885  }
886  public function rebinding($abstract, Closure $callback)
887  {
888  $this->reboundCallbacks[$abstract][] = $callback;
889  if ($this->bound($abstract)) {
890  return $this->make($abstract);
891  }
892  }
893  public function refresh($abstract, $target, $method)
894  {
895  return $this->rebinding($abstract, function ($app, $instance) use($target, $method) {
896  $target->{$method}($instance);
897  });
898  }
899  protected function rebound($abstract)
900  {
901  $instance = $this->make($abstract);
902  foreach ($this->getReboundCallbacks($abstract) as $callback) {
903  call_user_func($callback, $this, $instance);
904  }
905  }
906  protected function getReboundCallbacks($abstract)
907  {
908  if (isset($this->reboundCallbacks[$abstract])) {
909  return $this->reboundCallbacks[$abstract];
910  }
911  return array();
912  }
913  public function wrap(Closure $callback, array $parameters = array())
914  {
915  return function () use($callback, $parameters) {
916  return $this->call($callback, $parameters);
917  };
918  }
919  public function call($callback, array $parameters = array(), $defaultMethod = null)
920  {
921  if ($this->isCallableWithAtSign($callback) || $defaultMethod) {
922  return $this->callClass($callback, $parameters, $defaultMethod);
923  }
924  $dependencies = $this->getMethodDependencies($callback, $parameters);
925  return call_user_func_array($callback, $dependencies);
926  }
927  protected function isCallableWithAtSign($callback)
928  {
929  if (!is_string($callback)) {
930  return false;
931  }
932  return strpos($callback, '@') !== false;
933  }
934  protected function getMethodDependencies($callback, $parameters = array())
935  {
936  $dependencies = array();
937  foreach ($this->getCallReflector($callback)->getParameters() as $key => $parameter) {
938  $this->addDependencyForCallParameter($parameter, $parameters, $dependencies);
939  }
940  return array_merge($dependencies, $parameters);
941  }
942  protected function getCallReflector($callback)
943  {
944  if (is_string($callback) && strpos($callback, '::') !== false) {
945  $callback = explode('::', $callback);
946  }
947  if (is_array($callback)) {
948  return new ReflectionMethod($callback[0], $callback[1]);
949  }
950  return new ReflectionFunction($callback);
951  }
952  protected function addDependencyForCallParameter(ReflectionParameter $parameter, array &$parameters, &$dependencies)
953  {
954  if (array_key_exists($parameter->name, $parameters)) {
955  $dependencies[] = $parameters[$parameter->name];
956  unset($parameters[$parameter->name]);
957  } elseif ($parameter->getClass()) {
958  $dependencies[] = $this->make($parameter->getClass()->name);
959  } elseif ($parameter->isDefaultValueAvailable()) {
960  $dependencies[] = $parameter->getDefaultValue();
961  }
962  }
963  protected function callClass($target, array $parameters = array(), $defaultMethod = null)
964  {
965  $segments = explode('@', $target);
966  $method = count($segments) == 2 ? $segments[1] : $defaultMethod;
967  if (is_null($method)) {
968  throw new InvalidArgumentException('Method not provided.');
969  }
970  return $this->call(array($this->make($segments[0]), $method), $parameters);
971  }
972  public function make($abstract, $parameters = array())
973  {
974  $abstract = $this->getAlias($abstract);
975  if (isset($this->instances[$abstract])) {
976  return $this->instances[$abstract];
977  }
978  $concrete = $this->getConcrete($abstract);
979  if ($this->isBuildable($concrete, $abstract)) {
980  $object = $this->build($concrete, $parameters);
981  } else {
982  $object = $this->make($concrete, $parameters);
983  }
984  foreach ($this->getExtenders($abstract) as $extender) {
985  $object = $extender($object, $this);
986  }
987  if ($this->isShared($abstract)) {
988  $this->instances[$abstract] = $object;
989  }
990  $this->fireResolvingCallbacks($abstract, $object);
991  $this->resolved[$abstract] = true;
992  return $object;
993  }
994  protected function getConcrete($abstract)
995  {
996  if (!is_null($concrete = $this->getContextualConcrete($abstract))) {
997  return $concrete;
998  }
999  if (!isset($this->bindings[$abstract])) {
1000  if ($this->missingLeadingSlash($abstract) && isset($this->bindings['\\' . $abstract])) {
1001  $abstract = '\\' . $abstract;
1002  }
1003  return $abstract;
1004  }
1005  return $this->bindings[$abstract]['concrete'];
1006  }
1007  protected function getContextualConcrete($abstract)
1008  {
1009  if (isset($this->contextual[end($this->buildStack)][$abstract])) {
1010  return $this->contextual[end($this->buildStack)][$abstract];
1011  }
1012  }
1013  protected function missingLeadingSlash($abstract)
1014  {
1015  return is_string($abstract) && strpos($abstract, '\\') !== 0;
1016  }
1017  protected function getExtenders($abstract)
1018  {
1019  if (isset($this->extenders[$abstract])) {
1020  return $this->extenders[$abstract];
1021  }
1022  return array();
1023  }
1024  public function build($concrete, $parameters = array())
1025  {
1026  if ($concrete instanceof Closure) {
1027  return $concrete($this, $parameters);
1028  }
1029  $reflector = new ReflectionClass($concrete);
1030  if (!$reflector->isInstantiable()) {
1031  $message = "Target [{$concrete}] is not instantiable.";
1032  throw new BindingResolutionException($message);
1033  }
1034  $this->buildStack[] = $concrete;
1035  $constructor = $reflector->getConstructor();
1036  if (is_null($constructor)) {
1037  array_pop($this->buildStack);
1038  return new $concrete();
1039  }
1040  $dependencies = $constructor->getParameters();
1041  $parameters = $this->keyParametersByArgument($dependencies, $parameters);
1042  $instances = $this->getDependencies($dependencies, $parameters);
1043  array_pop($this->buildStack);
1044  return $reflector->newInstanceArgs($instances);
1045  }
1046  protected function getDependencies($parameters, array $primitives = array())
1047  {
1048  $dependencies = array();
1049  foreach ($parameters as $parameter) {
1050  $dependency = $parameter->getClass();
1051  if (array_key_exists($parameter->name, $primitives)) {
1052  $dependencies[] = $primitives[$parameter->name];
1053  } elseif (is_null($dependency)) {
1054  $dependencies[] = $this->resolveNonClass($parameter);
1055  } else {
1056  $dependencies[] = $this->resolveClass($parameter);
1057  }
1058  }
1059  return (array) $dependencies;
1060  }
1061  protected function resolveNonClass(ReflectionParameter $parameter)
1062  {
1063  if ($parameter->isDefaultValueAvailable()) {
1064  return $parameter->getDefaultValue();
1065  }
1066  $message = "Unresolvable dependency resolving [{$parameter}] in class {$parameter->getDeclaringClass()->getName()}";
1067  throw new BindingResolutionException($message);
1068  }
1069  protected function resolveClass(ReflectionParameter $parameter)
1070  {
1071  try {
1072  return $this->make($parameter->getClass()->name);
1073  } catch (BindingResolutionException $e) {
1074  if ($parameter->isOptional()) {
1075  return $parameter->getDefaultValue();
1076  }
1077  throw $e;
1078  }
1079  }
1080  protected function keyParametersByArgument(array $dependencies, array $parameters)
1081  {
1082  foreach ($parameters as $key => $value) {
1083  if (is_numeric($key)) {
1084  unset($parameters[$key]);
1085  $parameters[$dependencies[$key]->name] = $value;
1086  }
1087  }
1088  return $parameters;
1089  }
1090  public function resolving($abstract, Closure $callback = null)
1091  {
1092  if ($callback === null && $abstract instanceof Closure) {
1093  $this->resolvingCallback($abstract);
1094  } else {
1095  $this->resolvingCallbacks[$abstract][] = $callback;
1096  }
1097  }
1098  public function afterResolving($abstract, Closure $callback = null)
1099  {
1100  if ($abstract instanceof Closure && $callback === null) {
1101  $this->afterResolvingCallback($abstract);
1102  } else {
1103  $this->afterResolvingCallbacks[$abstract][] = $callback;
1104  }
1105  }
1106  protected function resolvingCallback(Closure $callback)
1107  {
1108  $abstract = $this->getFunctionHint($callback);
1109  if ($abstract) {
1110  $this->resolvingCallbacks[$abstract][] = $callback;
1111  } else {
1112  $this->globalResolvingCallbacks[] = $callback;
1113  }
1114  }
1115  protected function afterResolvingCallback(Closure $callback)
1116  {
1117  $abstract = $this->getFunctionHint($callback);
1118  if ($abstract) {
1119  $this->afterResolvingCallbacks[$abstract][] = $callback;
1120  } else {
1121  $this->globalAfterResolvingCallbacks[] = $callback;
1122  }
1123  }
1124  protected function getFunctionHint(Closure $callback)
1125  {
1126  $function = new ReflectionFunction($callback);
1127  if ($function->getNumberOfParameters() == 0) {
1128  return;
1129  }
1130  $expected = $function->getParameters()[0];
1131  if (!$expected->getClass()) {
1132  return;
1133  }
1134  return $expected->getClass()->name;
1135  }
1136  protected function fireResolvingCallbacks($abstract, $object)
1137  {
1138  $this->fireCallbackArray($object, $this->globalResolvingCallbacks);
1139  $this->fireCallbackArray($object, $this->getCallbacksForType($abstract, $object, $this->resolvingCallbacks));
1140  $this->fireCallbackArray($object, $this->globalAfterResolvingCallbacks);
1141  $this->fireCallbackArray($object, $this->getCallbacksForType($abstract, $object, $this->afterResolvingCallbacks));
1142  }
1143  protected function getCallbacksForType($abstract, $object, array $callbacksPerType)
1144  {
1145  $results = array();
1146  foreach ($callbacksPerType as $type => $callbacks) {
1147  if ($type === $abstract || $object instanceof $type) {
1148  $results = array_merge($results, $callbacks);
1149  }
1150  }
1151  return $results;
1152  }
1153  protected function fireCallbackArray($object, array $callbacks)
1154  {
1155  foreach ($callbacks as $callback) {
1156  $callback($object, $this);
1157  }
1158  }
1159  public function isShared($abstract)
1160  {
1161  if (isset($this->bindings[$abstract]['shared'])) {
1162  $shared = $this->bindings[$abstract]['shared'];
1163  } else {
1164  $shared = false;
1165  }
1166  return isset($this->instances[$abstract]) || $shared === true;
1167  }
1168  protected function isBuildable($concrete, $abstract)
1169  {
1170  return $concrete === $abstract || $concrete instanceof Closure;
1171  }
1172  protected function getAlias($abstract)
1173  {
1174  return isset($this->aliases[$abstract]) ? $this->aliases[$abstract] : $abstract;
1175  }
1176  public function getBindings()
1177  {
1178  return $this->bindings;
1179  }
1180  protected function dropStaleInstances($abstract)
1181  {
1182  unset($this->instances[$abstract], $this->aliases[$abstract]);
1183  }
1184  public function forgetInstance($abstract)
1185  {
1186  unset($this->instances[$abstract]);
1187  }
1188  public function forgetInstances()
1189  {
1190  $this->instances = array();
1191  }
1192  public function flush()
1193  {
1194  $this->aliases = array();
1195  $this->resolved = array();
1196  $this->bindings = array();
1197  $this->instances = array();
1198  }
1199  public static function getInstance()
1200  {
1201  return static::$instance;
1202  }
1203  public static function setInstance(ContainerContract $container)
1204  {
1205  static::$instance = $container;
1206  }
1207  public function offsetExists($key)
1208  {
1209  return isset($this->bindings[$key]);
1210  }
1211  public function offsetGet($key)
1212  {
1213  return $this->make($key);
1214  }
1215  public function offsetSet($key, $value)
1216  {
1217  if (!$value instanceof Closure) {
1218  $value = function () use($value) {
1219  return $value;
1220  };
1221  }
1222  $this->bind($key, $value);
1223  }
1224  public function offsetUnset($key)
1225  {
1226  unset($this->bindings[$key], $this->instances[$key], $this->resolved[$key]);
1227  }
1228  public function __get($key)
1229  {
1230  return $this[$key];
1231  }
1232  public function __set($key, $value)
1233  {
1234  $this[$key] = $value;
1235  }
1236 }
1238 
1242 {
1243  const MASTER_REQUEST = 1;
1244  const SUB_REQUEST = 2;
1245  public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true);
1246 }
1248 
1252 {
1253  public function terminate(Request $request, Response $response);
1254 }
1256 
1257 use Closure;
1269 class Application extends Container implements ApplicationContract, HttpKernelInterface
1270 {
1271  const VERSION = '5.0.27';
1272  protected $basePath;
1273  protected $hasBeenBootstrapped = false;
1274  protected $booted = false;
1275  protected $bootingCallbacks = array();
1276  protected $bootedCallbacks = array();
1277  protected $terminatingCallbacks = array();
1278  protected $serviceProviders = array();
1279  protected $loadedProviders = array();
1280  protected $deferredServices = array();
1281  protected $databasePath;
1282  protected $storagePath;
1283  protected $useStoragePathForOptimizations = false;
1284  protected $environmentFile = '.env';
1285  public function __construct($basePath = null)
1286  {
1287  $this->registerBaseBindings();
1288  $this->registerBaseServiceProviders();
1289  $this->registerCoreContainerAliases();
1290  if ($basePath) {
1291  $this->setBasePath($basePath);
1292  }
1293  }
1294  public function version()
1295  {
1296  return static::VERSION;
1297  }
1298  protected function registerBaseBindings()
1299  {
1300  static::setInstance($this);
1301  $this->instance('app', $this);
1302  $this->instance('Illuminate\\Container\\Container', $this);
1303  }
1304  protected function registerBaseServiceProviders()
1305  {
1306  $this->register(new EventServiceProvider($this));
1307  $this->register(new RoutingServiceProvider($this));
1308  }
1309  public function bootstrapWith(array $bootstrappers)
1310  {
1311  foreach ($bootstrappers as $bootstrapper) {
1312  $this['events']->fire('bootstrapping: ' . $bootstrapper, array($this));
1313  $this->make($bootstrapper)->bootstrap($this);
1314  $this['events']->fire('bootstrapped: ' . $bootstrapper, array($this));
1315  }
1316  $this->hasBeenBootstrapped = true;
1317  }
1318  public function afterLoadingEnvironment(Closure $callback)
1319  {
1320  return $this->afterBootstrapping('Illuminate\\Foundation\\Bootstrap\\DetectEnvironment', $callback);
1321  }
1322  public function beforeBootstrapping($bootstrapper, Closure $callback)
1323  {
1324  $this['events']->listen('bootstrapping: ' . $bootstrapper, $callback);
1325  }
1326  public function afterBootstrapping($bootstrapper, Closure $callback)
1327  {
1328  $this['events']->listen('bootstrapped: ' . $bootstrapper, $callback);
1329  }
1330  public function hasBeenBootstrapped()
1331  {
1332  return $this->hasBeenBootstrapped;
1333  }
1334  public function setBasePath($basePath)
1335  {
1336  $this->basePath = $basePath;
1337  $this->bindPathsInContainer();
1338  return $this;
1339  }
1340  protected function bindPathsInContainer()
1341  {
1342  $this->instance('path', $this->path());
1343  foreach (array('base', 'config', 'database', 'lang', 'public', 'storage') as $path) {
1344  $this->instance('path.' . $path, $this->{$path . 'Path'}());
1345  }
1346  }
1347  public function path()
1348  {
1349  return $this->basePath . DIRECTORY_SEPARATOR . 'app';
1350  }
1351  public function basePath()
1352  {
1353  return $this->basePath;
1354  }
1355  public function configPath()
1356  {
1357  return $this->basePath . DIRECTORY_SEPARATOR . 'config';
1358  }
1359  public function databasePath()
1360  {
1361  return $this->databasePath ?: $this->basePath . DIRECTORY_SEPARATOR . 'database';
1362  }
1363  public function useDatabasePath($path)
1364  {
1365  $this->databasePath = $path;
1366  $this->instance('path.database', $path);
1367  return $this;
1368  }
1369  public function langPath()
1370  {
1371  return $this->basePath . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'lang';
1372  }
1373  public function publicPath()
1374  {
1375  return $this->basePath . DIRECTORY_SEPARATOR . 'public';
1376  }
1377  public function storagePath()
1378  {
1379  return $this->storagePath ?: $this->basePath . DIRECTORY_SEPARATOR . 'storage';
1380  }
1381  public function useStoragePath($path)
1382  {
1383  $this->storagePath = $path;
1384  $this->instance('path.storage', $path);
1385  return $this;
1386  }
1387  public function loadEnvironmentFrom($file)
1388  {
1389  $this->environmentFile = $file;
1390  return $this;
1391  }
1392  public function environmentFile()
1393  {
1394  return $this->environmentFile ?: '.env';
1395  }
1396  public function environment()
1397  {
1398  if (func_num_args() > 0) {
1399  $patterns = is_array(func_get_arg(0)) ? func_get_arg(0) : func_get_args();
1400  foreach ($patterns as $pattern) {
1401  if (str_is($pattern, $this['env'])) {
1402  return true;
1403  }
1404  }
1405  return false;
1406  }
1407  return $this['env'];
1408  }
1409  public function isLocal()
1410  {
1411  return $this['env'] == 'local';
1412  }
1413  public function detectEnvironment(Closure $callback)
1414  {
1415  $args = isset($_SERVER['argv']) ? $_SERVER['argv'] : null;
1416  return $this['env'] = (new EnvironmentDetector())->detect($callback, $args);
1417  }
1418  public function runningInConsole()
1419  {
1420  return php_sapi_name() == 'cli';
1421  }
1422  public function runningUnitTests()
1423  {
1424  return $this['env'] == 'testing';
1425  }
1427  {
1428  $manifestPath = $this->getCachedServicesPath();
1429  (new ProviderRepository($this, new Filesystem(), $manifestPath))->load($this->config['app.providers']);
1430  }
1431  public function register($provider, $options = array(), $force = false)
1432  {
1433  if ($registered = $this->getProvider($provider) && !$force) {
1434  return $registered;
1435  }
1436  if (is_string($provider)) {
1437  $provider = $this->resolveProviderClass($provider);
1438  }
1439  $provider->register();
1440  foreach ($options as $key => $value) {
1441  $this[$key] = $value;
1442  }
1443  $this->markAsRegistered($provider);
1444  if ($this->booted) {
1445  $this->bootProvider($provider);
1446  }
1447  return $provider;
1448  }
1449  public function getProvider($provider)
1450  {
1451  $name = is_string($provider) ? $provider : get_class($provider);
1452  return array_first($this->serviceProviders, function ($key, $value) use($name) {
1453  return $value instanceof $name;
1454  });
1455  }
1456  public function resolveProviderClass($provider)
1457  {
1458  return new $provider($this);
1459  }
1460  protected function markAsRegistered($provider)
1461  {
1462  $this['events']->fire($class = get_class($provider), array($provider));
1463  $this->serviceProviders[] = $provider;
1464  $this->loadedProviders[$class] = true;
1465  }
1466  public function loadDeferredProviders()
1467  {
1468  foreach ($this->deferredServices as $service => $provider) {
1469  $this->loadDeferredProvider($service);
1470  }
1471  $this->deferredServices = array();
1472  }
1473  public function loadDeferredProvider($service)
1474  {
1475  if (!isset($this->deferredServices[$service])) {
1476  return;
1477  }
1478  $provider = $this->deferredServices[$service];
1479  if (!isset($this->loadedProviders[$provider])) {
1480  $this->registerDeferredProvider($provider, $service);
1481  }
1482  }
1483  public function registerDeferredProvider($provider, $service = null)
1484  {
1485  if ($service) {
1486  unset($this->deferredServices[$service]);
1487  }
1488  $this->register($instance = new $provider($this));
1489  if (!$this->booted) {
1490  $this->booting(function () use($instance) {
1491  $this->bootProvider($instance);
1492  });
1493  }
1494  }
1495  public function make($abstract, $parameters = array())
1496  {
1497  $abstract = $this->getAlias($abstract);
1498  if (isset($this->deferredServices[$abstract])) {
1499  $this->loadDeferredProvider($abstract);
1500  }
1501  return parent::make($abstract, $parameters);
1502  }
1503  public function bound($abstract)
1504  {
1505  return isset($this->deferredServices[$abstract]) || parent::bound($abstract);
1506  }
1507  public function isBooted()
1508  {
1509  return $this->booted;
1510  }
1511  public function boot()
1512  {
1513  if ($this->booted) {
1514  return;
1515  }
1516  $this->fireAppCallbacks($this->bootingCallbacks);
1517  array_walk($this->serviceProviders, function ($p) {
1518  $this->bootProvider($p);
1519  });
1520  $this->booted = true;
1521  $this->fireAppCallbacks($this->bootedCallbacks);
1522  }
1523  protected function bootProvider(ServiceProvider $provider)
1524  {
1525  if (method_exists($provider, 'boot')) {
1526  return $this->call(array($provider, 'boot'));
1527  }
1528  }
1529  public function booting($callback)
1530  {
1531  $this->bootingCallbacks[] = $callback;
1532  }
1533  public function booted($callback)
1534  {
1535  $this->bootedCallbacks[] = $callback;
1536  if ($this->isBooted()) {
1537  $this->fireAppCallbacks(array($callback));
1538  }
1539  }
1540  public function handle(SymfonyRequest $request, $type = self::MASTER_REQUEST, $catch = true)
1541  {
1542  return $this['Illuminate\\Contracts\\Http\\Kernel']->handle(Request::createFromBase($request));
1543  }
1544  public function configurationIsCached()
1545  {
1546  return $this['files']->exists($this->getCachedConfigPath());
1547  }
1548  public function getCachedConfigPath()
1549  {
1550  if ($this->vendorIsWritableForOptimizations()) {
1551  return $this->basePath() . '/vendor/config.php';
1552  } else {
1553  return $this['path.storage'] . '/framework/config.php';
1554  }
1555  }
1556  public function routesAreCached()
1557  {
1558  return $this['files']->exists($this->getCachedRoutesPath());
1559  }
1560  public function getCachedRoutesPath()
1561  {
1562  if ($this->vendorIsWritableForOptimizations()) {
1563  return $this->basePath() . '/vendor/routes.php';
1564  } else {
1565  return $this['path.storage'] . '/framework/routes.php';
1566  }
1567  }
1568  public function getCachedCompilePath()
1569  {
1570  if ($this->vendorIsWritableForOptimizations()) {
1571  return $this->basePath() . '/vendor/compiled.php';
1572  } else {
1573  return $this->storagePath() . '/framework/compiled.php';
1574  }
1575  }
1576  public function getCachedServicesPath()
1577  {
1578  if ($this->vendorIsWritableForOptimizations()) {
1579  return $this->basePath() . '/vendor/services.json';
1580  } else {
1581  return $this->storagePath() . '/framework/services.json';
1582  }
1583  }
1585  {
1586  if ($this->useStoragePathForOptimizations) {
1587  return false;
1588  }
1589  return is_writable($this->basePath() . '/vendor');
1590  }
1591  public function useStoragePathForOptimizations($value = true)
1592  {
1593  $this->useStoragePathForOptimizations = $value;
1594  return $this;
1595  }
1596  protected function fireAppCallbacks(array $callbacks)
1597  {
1598  foreach ($callbacks as $callback) {
1599  call_user_func($callback, $this);
1600  }
1601  }
1602  public function isDownForMaintenance()
1603  {
1604  return file_exists($this->storagePath() . DIRECTORY_SEPARATOR . 'framework' . DIRECTORY_SEPARATOR . 'down');
1605  }
1606  public function down(Closure $callback)
1607  {
1608  $this['events']->listen('illuminate.app.down', $callback);
1609  }
1610  public function abort($code, $message = '', array $headers = array())
1611  {
1612  if ($code == 404) {
1613  throw new NotFoundHttpException($message);
1614  }
1615  throw new HttpException($code, $message, null, $headers);
1616  }
1617  public function terminating(Closure $callback)
1618  {
1619  $this->terminatingCallbacks[] = $callback;
1620  return $this;
1621  }
1622  public function terminate()
1623  {
1624  foreach ($this->terminatingCallbacks as $terminating) {
1625  $this->call($terminating);
1626  }
1627  }
1628  public function getLoadedProviders()
1629  {
1630  return $this->loadedProviders;
1631  }
1632  public function setDeferredServices(array $services)
1633  {
1634  $this->deferredServices = $services;
1635  }
1636  public function isDeferredService($service)
1637  {
1638  return isset($this->deferredServices[$service]);
1639  }
1640  public function getLocale()
1641  {
1642  return $this['config']->get('app.locale');
1643  }
1644  public function setLocale($locale)
1645  {
1646  $this['config']->set('app.locale', $locale);
1647  $this['translator']->setLocale($locale);
1648  $this['events']->fire('locale.changed', array($locale));
1649  }
1651  {
1652  $aliases = array('app' => array('Illuminate\\Foundation\\Application', 'Illuminate\\Contracts\\Container\\Container', 'Illuminate\\Contracts\\Foundation\\Application'), 'artisan' => array('Illuminate\\Console\\Application', 'Illuminate\\Contracts\\Console\\Application'), 'auth' => 'Illuminate\\Auth\\AuthManager', 'auth.driver' => array('Illuminate\\Auth\\Guard', 'Illuminate\\Contracts\\Auth\\Guard'), 'auth.password.tokens' => 'Illuminate\\Auth\\Passwords\\TokenRepositoryInterface', 'blade.compiler' => 'Illuminate\\View\\Compilers\\BladeCompiler', 'cache' => array('Illuminate\\Cache\\CacheManager', 'Illuminate\\Contracts\\Cache\\Factory'), 'cache.store' => array('Illuminate\\Cache\\Repository', 'Illuminate\\Contracts\\Cache\\Repository'), 'config' => array('Illuminate\\Config\\Repository', 'Illuminate\\Contracts\\Config\\Repository'), 'cookie' => array('Illuminate\\Cookie\\CookieJar', 'Illuminate\\Contracts\\Cookie\\Factory', 'Illuminate\\Contracts\\Cookie\\QueueingFactory'), 'encrypter' => array('Illuminate\\Encryption\\Encrypter', 'Illuminate\\Contracts\\Encryption\\Encrypter'), 'db' => 'Illuminate\\Database\\DatabaseManager', 'events' => array('Illuminate\\Events\\Dispatcher', 'Illuminate\\Contracts\\Events\\Dispatcher'), 'files' => 'Illuminate\\Filesystem\\Filesystem', 'filesystem' => array('Illuminate\\Filesystem\\FilesystemManager', 'Illuminate\\Contracts\\Filesystem\\Factory'), 'filesystem.disk' => 'Illuminate\\Contracts\\Filesystem\\Filesystem', 'filesystem.cloud' => 'Illuminate\\Contracts\\Filesystem\\Cloud', 'hash' => 'Illuminate\\Contracts\\Hashing\\Hasher', 'translator' => array('Illuminate\\Translation\\Translator', 'Symfony\\Component\\Translation\\TranslatorInterface'), 'log' => array('Illuminate\\Log\\Writer', 'Illuminate\\Contracts\\Logging\\Log', 'Psr\\Log\\LoggerInterface'), 'mailer' => array('Illuminate\\Mail\\Mailer', 'Illuminate\\Contracts\\Mail\\Mailer', 'Illuminate\\Contracts\\Mail\\MailQueue'), 'paginator' => 'Illuminate\\Pagination\\Factory', 'auth.password' => array('Illuminate\\Auth\\Passwords\\PasswordBroker', 'Illuminate\\Contracts\\Auth\\PasswordBroker'), 'queue' => array('Illuminate\\Queue\\QueueManager', 'Illuminate\\Contracts\\Queue\\Factory', 'Illuminate\\Contracts\\Queue\\Monitor'), 'queue.connection' => 'Illuminate\\Contracts\\Queue\\Queue', 'redirect' => 'Illuminate\\Routing\\Redirector', 'redis' => array('Illuminate\\Redis\\Database', 'Illuminate\\Contracts\\Redis\\Database'), 'request' => 'Illuminate\\Http\\Request', 'router' => array('Illuminate\\Routing\\Router', 'Illuminate\\Contracts\\Routing\\Registrar'), 'session' => 'Illuminate\\Session\\SessionManager', 'session.store' => array('Illuminate\\Session\\Store', 'Symfony\\Component\\HttpFoundation\\Session\\SessionInterface'), 'url' => array('Illuminate\\Routing\\UrlGenerator', 'Illuminate\\Contracts\\Routing\\UrlGenerator'), 'validator' => array('Illuminate\\Validation\\Factory', 'Illuminate\\Contracts\\Validation\\Factory'), 'view' => array('Illuminate\\View\\Factory', 'Illuminate\\Contracts\\View\\Factory'));
1653  foreach ($aliases as $key => $aliases) {
1654  foreach ((array) $aliases as $alias) {
1655  $this->alias($key, $alias);
1656  }
1657  }
1658  }
1659  public function flush()
1660  {
1661  parent::flush();
1662  $this->loadedProviders = array();
1663  }
1664 }
1665 namespace Illuminate\Foundation;
1666 
1667 use Closure;
1669 {
1670  public function detect(Closure $callback, $consoleArgs = null)
1671  {
1672  if ($consoleArgs) {
1673  return $this->detectConsoleEnvironment($callback, $consoleArgs);
1674  }
1675  return $this->detectWebEnvironment($callback);
1676  }
1677  protected function detectWebEnvironment(Closure $callback)
1678  {
1679  return call_user_func($callback);
1680  }
1681  protected function detectConsoleEnvironment(Closure $callback, array $args)
1682  {
1683  if (!is_null($value = $this->getEnvironmentArgument($args))) {
1684  return head(array_slice(explode('=', $value), 1));
1685  }
1686  return $this->detectWebEnvironment($callback);
1687  }
1688  protected function getEnvironmentArgument(array $args)
1689  {
1690  return array_first($args, function ($k, $v) {
1691  return starts_with($v, '--env');
1692  });
1693  }
1694 }
1696 
1698 use Monolog\Logger as Monolog;
1701 {
1702  public function bootstrap(Application $app)
1703  {
1704  $this->configureHandlers($app, $this->registerLogger($app));
1705  $app->bind('Psr\\Log\\LoggerInterface', function ($app) {
1706  return $app['log']->getMonolog();
1707  });
1708  }
1709  protected function registerLogger(Application $app)
1710  {
1711  $app->instance('log', $log = new Writer(new Monolog($app->environment()), $app['events']));
1712  return $log;
1713  }
1714  protected function configureHandlers(Application $app, Writer $log)
1715  {
1716  $method = 'configure' . ucfirst($app['config']['app.log']) . 'Handler';
1717  $this->{$method}($app, $log);
1718  }
1719  protected function configureSingleHandler(Application $app, Writer $log)
1720  {
1721  $log->useFiles($app->storagePath() . '/logs/laravel.log');
1722  }
1723  protected function configureDailyHandler(Application $app, Writer $log)
1724  {
1725  $log->useDailyFiles($app->storagePath() . '/logs/laravel.log', $app->make('config')->get('app.log_max_files', 5));
1726  }
1727  protected function configureSyslogHandler(Application $app, Writer $log)
1728  {
1729  $log->useSyslog('laravel');
1730  }
1732  {
1733  $log->useErrorLog();
1734  }
1735 }
1737 
1738 use ErrorException;
1743 {
1744  protected $app;
1745  public function bootstrap(Application $app)
1746  {
1747  $this->app = $app;
1748  error_reporting(-1);
1749  set_error_handler(array($this, 'handleError'));
1750  set_exception_handler(array($this, 'handleException'));
1751  register_shutdown_function(array($this, 'handleShutdown'));
1752  if (!$app->environment('testing')) {
1753  ini_set('display_errors', 'Off');
1754  }
1755  }
1756  public function handleError($level, $message, $file = '', $line = 0, $context = array())
1757  {
1758  if (error_reporting() & $level) {
1759  throw new ErrorException($message, 0, $level, $file, $line);
1760  }
1761  }
1762  public function handleException($e)
1763  {
1764  $this->getExceptionHandler()->report($e);
1765  if ($this->app->runningInConsole()) {
1766  $this->renderForConsole($e);
1767  } else {
1768  $this->renderHttpResponse($e);
1769  }
1770  }
1771  protected function renderForConsole($e)
1772  {
1773  $this->getExceptionHandler()->renderForConsole(new ConsoleOutput(), $e);
1774  }
1775  protected function renderHttpResponse($e)
1776  {
1777  $this->getExceptionHandler()->render($this->app['request'], $e)->send();
1778  }
1779  public function handleShutdown()
1780  {
1781  if (!is_null($error = error_get_last()) && $this->isFatal($error['type'])) {
1782  $this->handleException($this->fatalExceptionFromError($error, 0));
1783  }
1784  }
1785  protected function fatalExceptionFromError(array $error, $traceOffset = null)
1786  {
1787  return new FatalErrorException($error['message'], $error['type'], 0, $error['file'], $error['line'], $traceOffset);
1788  }
1789  protected function isFatal($type)
1790  {
1791  return in_array($type, array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE));
1792  }
1793  protected function getExceptionHandler()
1794  {
1795  return $this->app->make('Illuminate\\Contracts\\Debug\\ExceptionHandler');
1796  }
1797 }
1799 
1804 {
1805  public function bootstrap(Application $app)
1806  {
1807  Facade::clearResolvedInstances();
1808  Facade::setFacadeApplication($app);
1809  AliasLoader::getInstance($app['config']['app.aliases'])->register();
1810  }
1811 }
1813 
1816 {
1817  public function bootstrap(Application $app)
1818  {
1820  }
1821 }
1823 
1826 {
1827  public function bootstrap(Application $app)
1828  {
1829  $app->boot();
1830  }
1831 }
1833 
1838 use Illuminate\Contracts\Config\Repository as RepositoryContract;
1840 {
1841  public function bootstrap(Application $app)
1842  {
1843  $items = array();
1844  if (file_exists($cached = $app->getCachedConfigPath())) {
1845  $items = (require $cached);
1846  $loadedFromCache = true;
1847  }
1848  $app->instance('config', $config = new Repository($items));
1849  if (!isset($loadedFromCache)) {
1850  $this->loadConfigurationFiles($app, $config);
1851  }
1852  date_default_timezone_set($config['app.timezone']);
1853  mb_internal_encoding('UTF-8');
1854  }
1855  protected function loadConfigurationFiles(Application $app, RepositoryContract $config)
1856  {
1857  foreach ($this->getConfigurationFiles($app) as $key => $path) {
1858  $config->set($key, require $path);
1859  }
1860  }
1862  {
1863  $files = array();
1864  foreach (Finder::create()->files()->name('*.php')->in($app->configPath()) as $file) {
1865  $nesting = $this->getConfigurationNesting($file);
1866  $files[$nesting . basename($file->getRealPath(), '.php')] = $file->getRealPath();
1867  }
1868  return $files;
1869  }
1870  private function getConfigurationNesting(SplFileInfo $file)
1871  {
1872  $directory = dirname($file->getRealPath());
1873  if ($tree = trim(str_replace(config_path(), '', $directory), DIRECTORY_SEPARATOR)) {
1874  $tree = str_replace(DIRECTORY_SEPARATOR, '.', $tree) . '.';
1875  }
1876  return $tree;
1877  }
1878 }
1880 
1881 use Dotenv;
1885 {
1886  public function bootstrap(Application $app)
1887  {
1888  try {
1889  Dotenv::load($app->basePath(), $app->environmentFile());
1890  } catch (InvalidArgumentException $e) {
1891  }
1892  $app->detectEnvironment(function () {
1893  return env('APP_ENV', 'production');
1894  });
1895  }
1896 }
1898 
1899 use Exception;
1905 use Illuminate\Contracts\Http\Kernel as KernelContract;
1906 class Kernel implements KernelContract
1907 {
1908  protected $app;
1909  protected $router;
1910  protected $bootstrappers = array('Illuminate\\Foundation\\Bootstrap\\DetectEnvironment', 'Illuminate\\Foundation\\Bootstrap\\LoadConfiguration', 'Illuminate\\Foundation\\Bootstrap\\ConfigureLogging', 'Illuminate\\Foundation\\Bootstrap\\HandleExceptions', 'Illuminate\\Foundation\\Bootstrap\\RegisterFacades', 'Illuminate\\Foundation\\Bootstrap\\RegisterProviders', 'Illuminate\\Foundation\\Bootstrap\\BootProviders');
1911  protected $middleware = array();
1912  protected $routeMiddleware = array();
1913  public function __construct(Application $app, Router $router)
1914  {
1915  $this->app = $app;
1916  $this->router = $router;
1917  foreach ($this->routeMiddleware as $key => $middleware) {
1918  $router->middleware($key, $middleware);
1919  }
1920  }
1921  public function handle($request)
1922  {
1923  try {
1924  $response = $this->sendRequestThroughRouter($request);
1925  } catch (Exception $e) {
1926  $this->reportException($e);
1927  $response = $this->renderException($request, $e);
1928  }
1929  $this->app['events']->fire('kernel.handled', array($request, $response));
1930  return $response;
1931  }
1932  protected function sendRequestThroughRouter($request)
1933  {
1934  $this->app->instance('request', $request);
1935  Facade::clearResolvedInstance('request');
1936  $this->bootstrap();
1937  return (new Pipeline($this->app))->send($request)->through($this->middleware)->then($this->dispatchToRouter());
1938  }
1939  public function terminate($request, $response)
1940  {
1941  $routeMiddlewares = $this->gatherRouteMiddlewares($request);
1942  foreach (array_merge($routeMiddlewares, $this->middleware) as $middleware) {
1943  $instance = $this->app->make($middleware);
1944  if ($instance instanceof TerminableMiddleware) {
1945  $instance->terminate($request, $response);
1946  }
1947  }
1948  $this->app->terminate();
1949  }
1950  protected function gatherRouteMiddlewares($request)
1951  {
1952  if ($request->route()) {
1953  return $this->router->gatherRouteMiddlewares($request->route());
1954  }
1955  return array();
1956  }
1957  public function prependMiddleware($middleware)
1958  {
1959  if (array_search($middleware, $this->middleware) === false) {
1960  array_unshift($this->middleware, $middleware);
1961  }
1962  return $this;
1963  }
1964  public function pushMiddleware($middleware)
1965  {
1966  if (array_search($middleware, $this->middleware) === false) {
1967  $this->middleware[] = $middleware;
1968  }
1969  return $this;
1970  }
1971  public function bootstrap()
1972  {
1973  if (!$this->app->hasBeenBootstrapped()) {
1974  $this->app->bootstrapWith($this->bootstrappers());
1975  }
1976  }
1977  protected function dispatchToRouter()
1978  {
1979  return function ($request) {
1980  $this->app->instance('request', $request);
1981  return $this->router->dispatch($request);
1982  };
1983  }
1984  protected function bootstrappers()
1985  {
1986  return $this->bootstrappers;
1987  }
1988  protected function reportException(Exception $e)
1989  {
1990  $this->app['Illuminate\\Contracts\\Debug\\ExceptionHandler']->report($e);
1991  }
1992  protected function renderException($request, Exception $e)
1993  {
1994  return $this->app['Illuminate\\Contracts\\Debug\\ExceptionHandler']->render($request, $e);
1995  }
1996  public function getApplication()
1997  {
1998  return $this->app;
1999  }
2000 }
2002 
2008  protected $auth;
2009  protected $registrar;
2010  public function getRegister()
2011  {
2012  return view('auth.register');
2013  }
2014  public function postRegister(Request $request)
2015  {
2016  $validator = $this->registrar->validator($request->all());
2017  if ($validator->fails()) {
2018  $this->throwValidationException($request, $validator);
2019  }
2020  $this->auth->login($this->registrar->create($request->all()));
2021  return redirect($this->redirectPath());
2022  }
2023  public function getLogin()
2024  {
2025  return view('auth.login');
2026  }
2027  public function postLogin(Request $request)
2028  {
2029  $this->validate($request, array('email' => 'required|email', 'password' => 'required'));
2030  $credentials = $request->only('email', 'password');
2031  if ($this->auth->attempt($credentials, $request->has('remember'))) {
2032  return redirect()->intended($this->redirectPath());
2033  }
2034  return redirect($this->loginPath())->withInput($request->only('email', 'remember'))->withErrors(array('email' => $this->getFailedLoginMessage()));
2035  }
2036  protected function getFailedLoginMessage()
2037  {
2038  return 'These credentials do not match our records.';
2039  }
2040  public function getLogout()
2041  {
2042  $this->auth->logout();
2043  return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/');
2044  }
2045  public function redirectPath()
2046  {
2047  if (property_exists($this, 'redirectPath')) {
2048  return $this->redirectPath;
2049  }
2050  return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
2051  }
2052  public function loginPath()
2053  {
2054  return property_exists($this, 'loginPath') ? $this->loginPath : '/auth/login';
2055  }
2056 }
2057 namespace Illuminate\Foundation\Auth;
2058 
2063 trait ResetsPasswords
2065  protected $auth;
2066  protected $passwords;
2067  public function getEmail()
2068  {
2069  return view('auth.password');
2070  }
2071  public function postEmail(Request $request)
2072  {
2073  $this->validate($request, array('email' => 'required|email'));
2074  $response = $this->passwords->sendResetLink($request->only('email'), function ($m) {
2075  $m->subject($this->getEmailSubject());
2076  });
2077  switch ($response) {
2079  return redirect()->back()->with('status', trans($response));
2081  return redirect()->back()->withErrors(array('email' => trans($response)));
2082  }
2083  }
2084  protected function getEmailSubject()
2085  {
2086  return isset($this->subject) ? $this->subject : 'Your Password Reset Link';
2087  }
2088  public function getReset($token = null)
2089  {
2090  if (is_null($token)) {
2091  throw new NotFoundHttpException();
2092  }
2093  return view('auth.reset')->with('token', $token);
2094  }
2095  public function postReset(Request $request)
2096  {
2097  $this->validate($request, array('token' => 'required', 'email' => 'required|email', 'password' => 'required|confirmed'));
2098  $credentials = $request->only('email', 'password', 'password_confirmation', 'token');
2099  $response = $this->passwords->reset($credentials, function ($user, $password) {
2100  $user->password = bcrypt($password);
2101  $user->save();
2102  $this->auth->login($user);
2103  });
2104  switch ($response) {
2106  return redirect($this->redirectPath());
2107  default:
2108  return redirect()->back()->withInput($request->only('email'))->withErrors(array('email' => trans($response)));
2109  }
2110  }
2111  public function redirectPath()
2112  {
2113  if (property_exists($this, 'redirectPath')) {
2114  return $this->redirectPath;
2115  }
2116  return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
2117  }
2118 }
2120 
2121 use Closure;
2122 use ArrayAccess;
2123 use SplFileInfo;
2124 use RuntimeException;
2126 use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
2127 class Request extends SymfonyRequest implements ArrayAccess
2128 {
2129  protected $json;
2130  protected $sessionStore;
2131  protected $userResolver;
2132  protected $routeResolver;
2133  public static function capture()
2134  {
2135  static::enableHttpMethodParameterOverride();
2136  return static::createFromBase(SymfonyRequest::createFromGlobals());
2137  }
2138  public function instance()
2139  {
2140  return $this;
2141  }
2142  public function method()
2143  {
2144  return $this->getMethod();
2145  }
2146  public function root()
2147  {
2148  return rtrim($this->getSchemeAndHttpHost() . $this->getBaseUrl(), '/');
2149  }
2150  public function url()
2151  {
2152  return rtrim(preg_replace('/\\?.*/', '', $this->getUri()), '/');
2153  }
2154  public function fullUrl()
2155  {
2156  $query = $this->getQueryString();
2157  return $query ? $this->url() . '?' . $query : $this->url();
2158  }
2159  public function path()
2160  {
2161  $pattern = trim($this->getPathInfo(), '/');
2162  return $pattern == '' ? '/' : $pattern;
2163  }
2164  public function decodedPath()
2165  {
2166  return rawurldecode($this->path());
2167  }
2168  public function segment($index, $default = null)
2169  {
2170  return array_get($this->segments(), $index - 1, $default);
2171  }
2172  public function segments()
2173  {
2174  $segments = explode('/', $this->path());
2175  return array_values(array_filter($segments, function ($v) {
2176  return $v != '';
2177  }));
2178  }
2179  public function is()
2180  {
2181  foreach (func_get_args() as $pattern) {
2182  if (str_is($pattern, urldecode($this->path()))) {
2183  return true;
2184  }
2185  }
2186  return false;
2187  }
2188  public function ajax()
2189  {
2190  return $this->isXmlHttpRequest();
2191  }
2192  public function pjax()
2193  {
2194  return $this->headers->get('X-PJAX') == true;
2195  }
2196  public function secure()
2197  {
2198  return $this->isSecure();
2199  }
2200  public function ip()
2201  {
2202  return $this->getClientIp();
2203  }
2204  public function ips()
2205  {
2206  return $this->getClientIps();
2207  }
2208  public function exists($key)
2209  {
2210  $keys = is_array($key) ? $key : func_get_args();
2211  $input = $this->all();
2212  foreach ($keys as $value) {
2213  if (!array_key_exists($value, $input)) {
2214  return false;
2215  }
2216  }
2217  return true;
2218  }
2219  public function has($key)
2220  {
2221  $keys = is_array($key) ? $key : func_get_args();
2222  foreach ($keys as $value) {
2223  if ($this->isEmptyString($value)) {
2224  return false;
2225  }
2226  }
2227  return true;
2228  }
2229  protected function isEmptyString($key)
2230  {
2231  $boolOrArray = is_bool($this->input($key)) || is_array($this->input($key));
2232  return !$boolOrArray && trim((string) $this->input($key)) === '';
2233  }
2234  public function all()
2235  {
2236  return array_replace_recursive($this->input(), $this->files->all());
2237  }
2238  public function input($key = null, $default = null)
2239  {
2240  $input = $this->getInputSource()->all() + $this->query->all();
2241  return array_get($input, $key, $default);
2242  }
2243  public function only($keys)
2244  {
2245  $keys = is_array($keys) ? $keys : func_get_args();
2246  $results = array();
2247  $input = $this->all();
2248  foreach ($keys as $key) {
2249  array_set($results, $key, array_get($input, $key));
2250  }
2251  return $results;
2252  }
2253  public function except($keys)
2254  {
2255  $keys = is_array($keys) ? $keys : func_get_args();
2256  $results = $this->all();
2257  array_forget($results, $keys);
2258  return $results;
2259  }
2260  public function query($key = null, $default = null)
2261  {
2262  return $this->retrieveItem('query', $key, $default);
2263  }
2264  public function hasCookie($key)
2265  {
2266  return !is_null($this->cookie($key));
2267  }
2268  public function cookie($key = null, $default = null)
2269  {
2270  return $this->retrieveItem('cookies', $key, $default);
2271  }
2272  public function file($key = null, $default = null)
2273  {
2274  return array_get($this->files->all(), $key, $default);
2275  }
2276  public function hasFile($key)
2277  {
2278  if (!is_array($files = $this->file($key))) {
2279  $files = array($files);
2280  }
2281  foreach ($files as $file) {
2282  if ($this->isValidFile($file)) {
2283  return true;
2284  }
2285  }
2286  return false;
2287  }
2288  protected function isValidFile($file)
2289  {
2290  return $file instanceof SplFileInfo && $file->getPath() != '';
2291  }
2292  public function header($key = null, $default = null)
2293  {
2294  return $this->retrieveItem('headers', $key, $default);
2295  }
2296  public function server($key = null, $default = null)
2297  {
2298  return $this->retrieveItem('server', $key, $default);
2299  }
2300  public function old($key = null, $default = null)
2301  {
2302  return $this->session()->getOldInput($key, $default);
2303  }
2304  public function flash($filter = null, $keys = array())
2305  {
2306  $flash = !is_null($filter) ? $this->{$filter}($keys) : $this->input();
2307  $this->session()->flashInput($flash);
2308  }
2309  public function flashOnly($keys)
2310  {
2311  $keys = is_array($keys) ? $keys : func_get_args();
2312  return $this->flash('only', $keys);
2313  }
2314  public function flashExcept($keys)
2315  {
2316  $keys = is_array($keys) ? $keys : func_get_args();
2317  return $this->flash('except', $keys);
2318  }
2319  public function flush()
2320  {
2321  $this->session()->flashInput(array());
2322  }
2323  protected function retrieveItem($source, $key, $default)
2324  {
2325  if (is_null($key)) {
2326  return $this->{$source}->all();
2327  }
2328  return $this->{$source}->get($key, $default, true);
2329  }
2330  public function merge(array $input)
2331  {
2332  $this->getInputSource()->add($input);
2333  }
2334  public function replace(array $input)
2335  {
2336  $this->getInputSource()->replace($input);
2337  }
2338  public function json($key = null, $default = null)
2339  {
2340  if (!isset($this->json)) {
2341  $this->json = new ParameterBag((array) json_decode($this->getContent(), true));
2342  }
2343  if (is_null($key)) {
2344  return $this->json;
2345  }
2346  return array_get($this->json->all(), $key, $default);
2347  }
2348  protected function getInputSource()
2349  {
2350  if ($this->isJson()) {
2351  return $this->json();
2352  }
2353  return $this->getMethod() == 'GET' ? $this->query : $this->request;
2354  }
2355  public function isJson()
2356  {
2357  return str_contains($this->header('CONTENT_TYPE'), '/json');
2358  }
2359  public function wantsJson()
2360  {
2361  $acceptable = $this->getAcceptableContentTypes();
2362  return isset($acceptable[0]) && $acceptable[0] == 'application/json';
2363  }
2364  public function format($default = 'html')
2365  {
2366  foreach ($this->getAcceptableContentTypes() as $type) {
2367  if ($format = $this->getFormat($type)) {
2368  return $format;
2369  }
2370  }
2371  return $default;
2372  }
2373  public static function createFromBase(SymfonyRequest $request)
2374  {
2375  if ($request instanceof static) {
2376  return $request;
2377  }
2378  $content = $request->content;
2379  $request = (new static())->duplicate($request->query->all(), $request->request->all(), $request->attributes->all(), $request->cookies->all(), $request->files->all(), $request->server->all());
2380  $request->content = $content;
2381  $request->request = $request->getInputSource();
2382  return $request;
2383  }
2384  public function duplicate(array $query = null, array $request = null, array $attributes = null, array $cookies = null, array $files = null, array $server = null)
2385  {
2386  return parent::duplicate($query, $request, $attributes, $cookies, array_filter((array) $files), $server);
2387  }
2388  public function session()
2389  {
2390  if (!$this->hasSession()) {
2391  throw new RuntimeException('Session store not set on request.');
2392  }
2393  return $this->getSession();
2394  }
2395  public function user()
2396  {
2397  return call_user_func($this->getUserResolver());
2398  }
2399  public function route()
2400  {
2401  if (func_num_args() == 1) {
2402  return $this->route()->parameter(func_get_arg(0));
2403  } else {
2404  return call_user_func($this->getRouteResolver());
2405  }
2406  }
2407  public function getUserResolver()
2408  {
2409  return $this->userResolver ?: function () {
2410  };
2411  }
2412  public function setUserResolver(Closure $callback)
2413  {
2414  $this->userResolver = $callback;
2415  return $this;
2416  }
2417  public function getRouteResolver()
2418  {
2419  return $this->routeResolver ?: function () {
2420  };
2421  }
2422  public function setRouteResolver(Closure $callback)
2423  {
2424  $this->routeResolver = $callback;
2425  return $this;
2426  }
2427  public function offsetExists($offset)
2428  {
2429  return array_key_exists($offset, $this->all());
2430  }
2431  public function offsetGet($offset)
2432  {
2433  return $this->input($offset);
2434  }
2435  public function offsetSet($offset, $value)
2436  {
2437  return $this->getInputSource()->set($offset, $value);
2438  }
2439  public function offsetUnset($offset)
2440  {
2441  return $this->getInputSource()->remove($offset);
2442  }
2443  public function __get($key)
2444  {
2445  $input = $this->input();
2446  if (array_key_exists($key, $input)) {
2447  return $this->input($key);
2448  } elseif (!is_null($this->route())) {
2449  return $this->route()->parameter($key);
2450  }
2451  }
2452 }
2454 
2455 use Closure;
2457 class FrameGuard implements Middleware
2458 {
2459  public function handle($request, Closure $next)
2460  {
2461  $response = $next($request);
2462  $response->headers->set('X-Frame-Options', 'SAMEORIGIN', false);
2463  return $response;
2464  }
2465 }
2467 
2468 use Closure;
2474 class VerifyCsrfToken implements Middleware
2475 {
2476  protected $encrypter;
2477  public function __construct(Encrypter $encrypter)
2478  {
2479  $this->encrypter = $encrypter;
2480  }
2481  public function handle($request, Closure $next)
2482  {
2483  if ($this->isReading($request) || $this->tokensMatch($request)) {
2484  return $this->addCookieToResponse($request, $next($request));
2485  }
2486  throw new TokenMismatchException();
2487  }
2488  protected function tokensMatch($request)
2489  {
2490  $token = $request->input('_token') ?: $request->header('X-CSRF-TOKEN');
2491  if (!$token && ($header = $request->header('X-XSRF-TOKEN'))) {
2492  $token = $this->encrypter->decrypt($header);
2493  }
2494  return StringUtils::equals($request->session()->token(), $token);
2495  }
2496  protected function addCookieToResponse($request, $response)
2497  {
2498  $response->headers->setCookie(new Cookie('XSRF-TOKEN', $request->session()->token(), time() + 60 * 120, '/', null, false, false));
2499  return $response;
2500  }
2501  protected function isReading($request)
2502  {
2503  return in_array($request->method(), array('HEAD', 'GET', 'OPTIONS'));
2504  }
2505 }
2507 
2508 use Closure;
2513 {
2514  protected $app;
2515  public function __construct(Application $app)
2516  {
2517  $this->app = $app;
2518  }
2519  public function handle($request, Closure $next)
2520  {
2521  if ($this->app->isDownForMaintenance()) {
2522  throw new HttpException(503);
2523  }
2524  return $next($request);
2525  }
2526 }
2528 
2530 class Request
2531 {
2532  const HEADER_CLIENT_IP = 'client_ip';
2533  const HEADER_CLIENT_HOST = 'client_host';
2534  const HEADER_CLIENT_PROTO = 'client_proto';
2535  const HEADER_CLIENT_PORT = 'client_port';
2536  const METHOD_HEAD = 'HEAD';
2537  const METHOD_GET = 'GET';
2538  const METHOD_POST = 'POST';
2539  const METHOD_PUT = 'PUT';
2540  const METHOD_PATCH = 'PATCH';
2541  const METHOD_DELETE = 'DELETE';
2542  const METHOD_PURGE = 'PURGE';
2543  const METHOD_OPTIONS = 'OPTIONS';
2544  const METHOD_TRACE = 'TRACE';
2545  const METHOD_CONNECT = 'CONNECT';
2546  protected static $trustedProxies = array();
2547  protected static $trustedHostPatterns = array();
2548  protected static $trustedHosts = array();
2549  protected static $trustedHeaders = array(self::HEADER_CLIENT_IP => 'X_FORWARDED_FOR', self::HEADER_CLIENT_HOST => 'X_FORWARDED_HOST', self::HEADER_CLIENT_PROTO => 'X_FORWARDED_PROTO', self::HEADER_CLIENT_PORT => 'X_FORWARDED_PORT');
2550  protected static $httpMethodParameterOverride = false;
2551  public $attributes;
2552  public $request;
2553  public $query;
2554  public $server;
2555  public $files;
2556  public $cookies;
2557  public $headers;
2558  protected $content;
2559  protected $languages;
2560  protected $charsets;
2561  protected $encodings;
2563  protected $pathInfo;
2564  protected $requestUri;
2565  protected $baseUrl;
2566  protected $basePath;
2567  protected $method;
2568  protected $format;
2569  protected $session;
2570  protected $locale;
2571  protected $defaultLocale = 'en';
2572  protected static $formats;
2573  protected static $requestFactory;
2574  public function __construct(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
2575  {
2576  $this->initialize($query, $request, $attributes, $cookies, $files, $server, $content);
2577  }
2578  public function initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
2579  {
2580  $this->request = new ParameterBag($request);
2581  $this->query = new ParameterBag($query);
2582  $this->attributes = new ParameterBag($attributes);
2583  $this->cookies = new ParameterBag($cookies);
2584  $this->files = new FileBag($files);
2585  $this->server = new ServerBag($server);
2586  $this->headers = new HeaderBag($this->server->getHeaders());
2587  $this->content = $content;
2588  $this->languages = null;
2589  $this->charsets = null;
2590  $this->encodings = null;
2591  $this->acceptableContentTypes = null;
2592  $this->pathInfo = null;
2593  $this->requestUri = null;
2594  $this->baseUrl = null;
2595  $this->basePath = null;
2596  $this->method = null;
2597  $this->format = null;
2598  }
2599  public static function createFromGlobals()
2600  {
2601  $server = $_SERVER;
2602  if ('cli-server' === php_sapi_name()) {
2603  if (array_key_exists('HTTP_CONTENT_LENGTH', $_SERVER)) {
2604  $server['CONTENT_LENGTH'] = $_SERVER['HTTP_CONTENT_LENGTH'];
2605  }
2606  if (array_key_exists('HTTP_CONTENT_TYPE', $_SERVER)) {
2607  $server['CONTENT_TYPE'] = $_SERVER['HTTP_CONTENT_TYPE'];
2608  }
2609  }
2610  $request = self::createRequestFromFactory($_GET, $_POST, array(), $_COOKIE, $_FILES, $server);
2611  if (0 === strpos($request->headers->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded') && in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), array('PUT', 'DELETE', 'PATCH'))) {
2612  parse_str($request->getContent(), $data);
2613  $request->request = new ParameterBag($data);
2614  }
2615  return $request;
2616  }
2617  public static function create($uri, $method = 'GET', $parameters = array(), $cookies = array(), $files = array(), $server = array(), $content = null)
2618  {
2619  $server = array_replace(array('SERVER_NAME' => 'localhost', 'SERVER_PORT' => 80, 'HTTP_HOST' => 'localhost', 'HTTP_USER_AGENT' => 'Symfony/2.X', 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5', 'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'REMOTE_ADDR' => '127.0.0.1', 'SCRIPT_NAME' => '', 'SCRIPT_FILENAME' => '', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'REQUEST_TIME' => time()), $server);
2620  $server['PATH_INFO'] = '';
2621  $server['REQUEST_METHOD'] = strtoupper($method);
2622  $components = parse_url($uri);
2623  if (isset($components['host'])) {
2624  $server['SERVER_NAME'] = $components['host'];
2625  $server['HTTP_HOST'] = $components['host'];
2626  }
2627  if (isset($components['scheme'])) {
2628  if ('https' === $components['scheme']) {
2629  $server['HTTPS'] = 'on';
2630  $server['SERVER_PORT'] = 443;
2631  } else {
2632  unset($server['HTTPS']);
2633  $server['SERVER_PORT'] = 80;
2634  }
2635  }
2636  if (isset($components['port'])) {
2637  $server['SERVER_PORT'] = $components['port'];
2638  $server['HTTP_HOST'] = $server['HTTP_HOST'] . ':' . $components['port'];
2639  }
2640  if (isset($components['user'])) {
2641  $server['PHP_AUTH_USER'] = $components['user'];
2642  }
2643  if (isset($components['pass'])) {
2644  $server['PHP_AUTH_PW'] = $components['pass'];
2645  }
2646  if (!isset($components['path'])) {
2647  $components['path'] = '/';
2648  }
2649  switch (strtoupper($method)) {
2650  case 'POST':
2651  case 'PUT':
2652  case 'DELETE':
2653  if (!isset($server['CONTENT_TYPE'])) {
2654  $server['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
2655  }
2656  case 'PATCH':
2657  $request = $parameters;
2658  $query = array();
2659  break;
2660  default:
2661  $request = array();
2662  $query = $parameters;
2663  break;
2664  }
2665  $queryString = '';
2666  if (isset($components['query'])) {
2667  parse_str(html_entity_decode($components['query']), $qs);
2668  if ($query) {
2669  $query = array_replace($qs, $query);
2670  $queryString = http_build_query($query, '', '&');
2671  } else {
2672  $query = $qs;
2673  $queryString = $components['query'];
2674  }
2675  } elseif ($query) {
2676  $queryString = http_build_query($query, '', '&');
2677  }
2678  $server['REQUEST_URI'] = $components['path'] . ('' !== $queryString ? '?' . $queryString : '');
2679  $server['QUERY_STRING'] = $queryString;
2680  return self::createRequestFromFactory($query, $request, array(), $cookies, $files, $server, $content);
2681  }
2682  public static function setFactory($callable)
2683  {
2684  self::$requestFactory = $callable;
2685  }
2686  public function duplicate(array $query = null, array $request = null, array $attributes = null, array $cookies = null, array $files = null, array $server = null)
2687  {
2688  $dup = clone $this;
2689  if ($query !== null) {
2690  $dup->query = new ParameterBag($query);
2691  }
2692  if ($request !== null) {
2693  $dup->request = new ParameterBag($request);
2694  }
2695  if ($attributes !== null) {
2696  $dup->attributes = new ParameterBag($attributes);
2697  }
2698  if ($cookies !== null) {
2699  $dup->cookies = new ParameterBag($cookies);
2700  }
2701  if ($files !== null) {
2702  $dup->files = new FileBag($files);
2703  }
2704  if ($server !== null) {
2705  $dup->server = new ServerBag($server);
2706  $dup->headers = new HeaderBag($dup->server->getHeaders());
2707  }
2708  $dup->languages = null;
2709  $dup->charsets = null;
2710  $dup->encodings = null;
2711  $dup->acceptableContentTypes = null;
2712  $dup->pathInfo = null;
2713  $dup->requestUri = null;
2714  $dup->baseUrl = null;
2715  $dup->basePath = null;
2716  $dup->method = null;
2717  $dup->format = null;
2718  if (!$dup->get('_format') && $this->get('_format')) {
2719  $dup->attributes->set('_format', $this->get('_format'));
2720  }
2721  if (!$dup->getRequestFormat(null)) {
2722  $dup->setRequestFormat($this->getRequestFormat(null));
2723  }
2724  return $dup;
2725  }
2726  public function __clone()
2727  {
2728  $this->query = clone $this->query;
2729  $this->request = clone $this->request;
2730  $this->attributes = clone $this->attributes;
2731  $this->cookies = clone $this->cookies;
2732  $this->files = clone $this->files;
2733  $this->server = clone $this->server;
2734  $this->headers = clone $this->headers;
2735  }
2736  public function __toString()
2737  {
2738  return sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL')) . '
2739 ' . $this->headers . '
2740 ' . $this->getContent();
2741  }
2742  public function overrideGlobals()
2743  {
2744  $this->server->set('QUERY_STRING', static::normalizeQueryString(http_build_query($this->query->all(), null, '&')));
2745  $_GET = $this->query->all();
2746  $_POST = $this->request->all();
2747  $_SERVER = $this->server->all();
2748  $_COOKIE = $this->cookies->all();
2749  foreach ($this->headers->all() as $key => $value) {
2750  $key = strtoupper(str_replace('-', '_', $key));
2751  if (in_array($key, array('CONTENT_TYPE', 'CONTENT_LENGTH'))) {
2752  $_SERVER[$key] = implode(', ', $value);
2753  } else {
2754  $_SERVER['HTTP_' . $key] = implode(', ', $value);
2755  }
2756  }
2757  $request = array('g' => $_GET, 'p' => $_POST, 'c' => $_COOKIE);
2758  $requestOrder = ini_get('request_order') ?: ini_get('variables_order');
2759  $requestOrder = preg_replace('#[^cgp]#', '', strtolower($requestOrder)) ?: 'gp';
2760  $_REQUEST = array();
2761  foreach (str_split($requestOrder) as $order) {
2762  $_REQUEST = array_merge($_REQUEST, $request[$order]);
2763  }
2764  }
2765  public static function setTrustedProxies(array $proxies)
2766  {
2767  self::$trustedProxies = $proxies;
2768  }
2769  public static function getTrustedProxies()
2770  {
2771  return self::$trustedProxies;
2772  }
2773  public static function setTrustedHosts(array $hostPatterns)
2774  {
2775  self::$trustedHostPatterns = array_map(function ($hostPattern) {
2776  return sprintf('{%s}i', str_replace('}', '\\}', $hostPattern));
2777  }, $hostPatterns);
2778  self::$trustedHosts = array();
2779  }
2780  public static function getTrustedHosts()
2781  {
2782  return self::$trustedHostPatterns;
2783  }
2784  public static function setTrustedHeaderName($key, $value)
2785  {
2786  if (!array_key_exists($key, self::$trustedHeaders)) {
2787  throw new \InvalidArgumentException(sprintf('Unable to set the trusted header name for key "%s".', $key));
2788  }
2789  self::$trustedHeaders[$key] = $value;
2790  }
2791  public static function getTrustedHeaderName($key)
2792  {
2793  if (!array_key_exists($key, self::$trustedHeaders)) {
2794  throw new \InvalidArgumentException(sprintf('Unable to get the trusted header name for key "%s".', $key));
2795  }
2796  return self::$trustedHeaders[$key];
2797  }
2798  public static function normalizeQueryString($qs)
2799  {
2800  if ('' == $qs) {
2801  return '';
2802  }
2803  $parts = array();
2804  $order = array();
2805  foreach (explode('&', $qs) as $param) {
2806  if ('' === $param || '=' === $param[0]) {
2807  continue;
2808  }
2809  $keyValuePair = explode('=', $param, 2);
2810  $parts[] = isset($keyValuePair[1]) ? rawurlencode(urldecode($keyValuePair[0])) . '=' . rawurlencode(urldecode($keyValuePair[1])) : rawurlencode(urldecode($keyValuePair[0]));
2811  $order[] = urldecode($keyValuePair[0]);
2812  }
2813  array_multisort($order, SORT_ASC, $parts);
2814  return implode('&', $parts);
2815  }
2816  public static function enableHttpMethodParameterOverride()
2817  {
2818  self::$httpMethodParameterOverride = true;
2819  }
2820  public static function getHttpMethodParameterOverride()
2821  {
2822  return self::$httpMethodParameterOverride;
2823  }
2824  public function get($key, $default = null, $deep = false)
2825  {
2826  if ($this !== ($result = $this->query->get($key, $this, $deep))) {
2827  return $result;
2828  }
2829  if ($this !== ($result = $this->attributes->get($key, $this, $deep))) {
2830  return $result;
2831  }
2832  if ($this !== ($result = $this->request->get($key, $this, $deep))) {
2833  return $result;
2834  }
2835  return $default;
2836  }
2837  public function getSession()
2838  {
2839  return $this->session;
2840  }
2841  public function hasPreviousSession()
2842  {
2843  return $this->hasSession() && $this->cookies->has($this->session->getName());
2844  }
2845  public function hasSession()
2846  {
2847  return null !== $this->session;
2848  }
2849  public function setSession(SessionInterface $session)
2850  {
2851  $this->session = $session;
2852  }
2853  public function getClientIps()
2854  {
2855  $ip = $this->server->get('REMOTE_ADDR');
2856  if (!$this->isFromTrustedProxy()) {
2857  return array($ip);
2858  }
2859  if (!self::$trustedHeaders[self::HEADER_CLIENT_IP] || !$this->headers->has(self::$trustedHeaders[self::HEADER_CLIENT_IP])) {
2860  return array($ip);
2861  }
2862  $clientIps = array_map('trim', explode(',', $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_IP])));
2863  $clientIps[] = $ip;
2864  $ip = $clientIps[0];
2865  foreach ($clientIps as $key => $clientIp) {
2866  if (preg_match('{((?:\\d+\\.){3}\\d+)\\:\\d+}', $clientIp, $match)) {
2867  $clientIps[$key] = $clientIp = $match[1];
2868  }
2869  if (IpUtils::checkIp($clientIp, self::$trustedProxies)) {
2870  unset($clientIps[$key]);
2871  }
2872  }
2873  return $clientIps ? array_reverse($clientIps) : array($ip);
2874  }
2875  public function getClientIp()
2876  {
2877  $ipAddresses = $this->getClientIps();
2878  return $ipAddresses[0];
2879  }
2880  public function getScriptName()
2881  {
2882  return $this->server->get('SCRIPT_NAME', $this->server->get('ORIG_SCRIPT_NAME', ''));
2883  }
2884  public function getPathInfo()
2885  {
2886  if (null === $this->pathInfo) {
2887  $this->pathInfo = $this->preparePathInfo();
2888  }
2889  return $this->pathInfo;
2890  }
2891  public function getBasePath()
2892  {
2893  if (null === $this->basePath) {
2894  $this->basePath = $this->prepareBasePath();
2895  }
2896  return $this->basePath;
2897  }
2898  public function getBaseUrl()
2899  {
2900  if (null === $this->baseUrl) {
2901  $this->baseUrl = $this->prepareBaseUrl();
2902  }
2903  return $this->baseUrl;
2904  }
2905  public function getScheme()
2906  {
2907  return $this->isSecure() ? 'https' : 'http';
2908  }
2909  public function getPort()
2910  {
2911  if ($this->isFromTrustedProxy()) {
2912  if (self::$trustedHeaders[self::HEADER_CLIENT_PORT] && ($port = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PORT]))) {
2913  return $port;
2914  }
2915  if (self::$trustedHeaders[self::HEADER_CLIENT_PROTO] && 'https' === $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PROTO], 'http')) {
2916  return 443;
2917  }
2918  }
2919  if ($host = $this->headers->get('HOST')) {
2920  if ($host[0] === '[') {
2921  $pos = strpos($host, ':', strrpos($host, ']'));
2922  } else {
2923  $pos = strrpos($host, ':');
2924  }
2925  if (false !== $pos) {
2926  return (int) substr($host, $pos + 1);
2927  }
2928  return 'https' === $this->getScheme() ? 443 : 80;
2929  }
2930  return $this->server->get('SERVER_PORT');
2931  }
2932  public function getUser()
2933  {
2934  return $this->headers->get('PHP_AUTH_USER');
2935  }
2936  public function getPassword()
2937  {
2938  return $this->headers->get('PHP_AUTH_PW');
2939  }
2940  public function getUserInfo()
2941  {
2942  $userinfo = $this->getUser();
2943  $pass = $this->getPassword();
2944  if ('' != $pass) {
2945  $userinfo .= ":{$pass}";
2946  }
2947  return $userinfo;
2948  }
2949  public function getHttpHost()
2950  {
2951  $scheme = $this->getScheme();
2952  $port = $this->getPort();
2953  if ('http' == $scheme && $port == 80 || 'https' == $scheme && $port == 443) {
2954  return $this->getHost();
2955  }
2956  return $this->getHost() . ':' . $port;
2957  }
2958  public function getRequestUri()
2959  {
2960  if (null === $this->requestUri) {
2961  $this->requestUri = $this->prepareRequestUri();
2962  }
2963  return $this->requestUri;
2964  }
2965  public function getSchemeAndHttpHost()
2966  {
2967  return $this->getScheme() . '://' . $this->getHttpHost();
2968  }
2969  public function getUri()
2970  {
2971  if (null !== ($qs = $this->getQueryString())) {
2972  $qs = '?' . $qs;
2973  }
2974  return $this->getSchemeAndHttpHost() . $this->getBaseUrl() . $this->getPathInfo() . $qs;
2975  }
2976  public function getUriForPath($path)
2977  {
2978  return $this->getSchemeAndHttpHost() . $this->getBaseUrl() . $path;
2979  }
2980  public function getQueryString()
2981  {
2982  $qs = static::normalizeQueryString($this->server->get('QUERY_STRING'));
2983  return '' === $qs ? null : $qs;
2984  }
2985  public function isSecure()
2986  {
2987  if ($this->isFromTrustedProxy() && self::$trustedHeaders[self::HEADER_CLIENT_PROTO] && ($proto = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PROTO]))) {
2988  return in_array(strtolower(current(explode(',', $proto))), array('https', 'on', 'ssl', '1'));
2989  }
2990  $https = $this->server->get('HTTPS');
2991  return !empty($https) && 'off' !== strtolower($https);
2992  }
2993  public function getHost()
2994  {
2995  if ($this->isFromTrustedProxy() && self::$trustedHeaders[self::HEADER_CLIENT_HOST] && ($host = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_HOST]))) {
2996  $elements = explode(',', $host);
2997  $host = $elements[count($elements) - 1];
2998  } elseif (!($host = $this->headers->get('HOST'))) {
2999  if (!($host = $this->server->get('SERVER_NAME'))) {
3000  $host = $this->server->get('SERVER_ADDR', '');
3001  }
3002  }
3003  $host = strtolower(preg_replace('/:\\d+$/', '', trim($host)));
3004  if ($host && '' !== preg_replace('/(?:^\\[)?[a-zA-Z0-9-:\\]_]+\\.?/', '', $host)) {
3005  throw new \UnexpectedValueException(sprintf('Invalid Host "%s"', $host));
3006  }
3007  if (count(self::$trustedHostPatterns) > 0) {
3008  if (in_array($host, self::$trustedHosts)) {
3009  return $host;
3010  }
3011  foreach (self::$trustedHostPatterns as $pattern) {
3012  if (preg_match($pattern, $host)) {
3013  self::$trustedHosts[] = $host;
3014  return $host;
3015  }
3016  }
3017  throw new \UnexpectedValueException(sprintf('Untrusted Host "%s"', $host));
3018  }
3019  return $host;
3020  }
3021  public function setMethod($method)
3022  {
3023  $this->method = null;
3024  $this->server->set('REQUEST_METHOD', $method);
3025  }
3026  public function getMethod()
3027  {
3028  if (null === $this->method) {
3029  $this->method = strtoupper($this->server->get('REQUEST_METHOD', 'GET'));
3030  if ('POST' === $this->method) {
3031  if ($method = $this->headers->get('X-HTTP-METHOD-OVERRIDE')) {
3032  $this->method = strtoupper($method);
3033  } elseif (self::$httpMethodParameterOverride) {
3034  $this->method = strtoupper($this->request->get('_method', $this->query->get('_method', 'POST')));
3035  }
3036  }
3037  }
3038  return $this->method;
3039  }
3040  public function getRealMethod()
3041  {
3042  return strtoupper($this->server->get('REQUEST_METHOD', 'GET'));
3043  }
3044  public function getMimeType($format)
3045  {
3046  if (null === static::$formats) {
3047  static::initializeFormats();
3048  }
3049  return isset(static::$formats[$format]) ? static::$formats[$format][0] : null;
3050  }
3051  public function getFormat($mimeType)
3052  {
3053  if (false !== ($pos = strpos($mimeType, ';'))) {
3054  $mimeType = substr($mimeType, 0, $pos);
3055  }
3056  if (null === static::$formats) {
3057  static::initializeFormats();
3058  }
3059  foreach (static::$formats as $format => $mimeTypes) {
3060  if (in_array($mimeType, (array) $mimeTypes)) {
3061  return $format;
3062  }
3063  }
3064  }
3065  public function setFormat($format, $mimeTypes)
3066  {
3067  if (null === static::$formats) {
3068  static::initializeFormats();
3069  }
3070  static::$formats[$format] = is_array($mimeTypes) ? $mimeTypes : array($mimeTypes);
3071  }
3072  public function getRequestFormat($default = 'html')
3073  {
3074  if (null === $this->format) {
3075  $this->format = $this->get('_format', $default);
3076  }
3077  return $this->format;
3078  }
3079  public function setRequestFormat($format)
3080  {
3081  $this->format = $format;
3082  }
3083  public function getContentType()
3084  {
3085  return $this->getFormat($this->headers->get('CONTENT_TYPE'));
3086  }
3087  public function setDefaultLocale($locale)
3088  {
3089  $this->defaultLocale = $locale;
3090  if (null === $this->locale) {
3091  $this->setPhpDefaultLocale($locale);
3092  }
3093  }
3094  public function getDefaultLocale()
3095  {
3096  return $this->defaultLocale;
3097  }
3098  public function setLocale($locale)
3099  {
3100  $this->setPhpDefaultLocale($this->locale = $locale);
3101  }
3102  public function getLocale()
3103  {
3104  return null === $this->locale ? $this->defaultLocale : $this->locale;
3105  }
3106  public function isMethod($method)
3107  {
3108  return $this->getMethod() === strtoupper($method);
3109  }
3110  public function isMethodSafe()
3111  {
3112  return in_array($this->getMethod(), array('GET', 'HEAD'));
3113  }
3114  public function getContent($asResource = false)
3115  {
3116  if (false === $this->content || true === $asResource && null !== $this->content) {
3117  throw new \LogicException('getContent() can only be called once when using the resource return type.');
3118  }
3119  if (true === $asResource) {
3120  $this->content = false;
3121  return fopen('php://input', 'rb');
3122  }
3123  if (null === $this->content) {
3124  $this->content = file_get_contents('php://input');
3125  }
3126  return $this->content;
3127  }
3128  public function getETags()
3129  {
3130  return preg_split('/\\s*,\\s*/', $this->headers->get('if_none_match'), null, PREG_SPLIT_NO_EMPTY);
3131  }
3132  public function isNoCache()
3133  {
3134  return $this->headers->hasCacheControlDirective('no-cache') || 'no-cache' == $this->headers->get('Pragma');
3135  }
3136  public function getPreferredLanguage(array $locales = null)
3137  {
3138  $preferredLanguages = $this->getLanguages();
3139  if (empty($locales)) {
3140  return isset($preferredLanguages[0]) ? $preferredLanguages[0] : null;
3141  }
3142  if (!$preferredLanguages) {
3143  return $locales[0];
3144  }
3145  $extendedPreferredLanguages = array();
3146  foreach ($preferredLanguages as $language) {
3147  $extendedPreferredLanguages[] = $language;
3148  if (false !== ($position = strpos($language, '_'))) {
3149  $superLanguage = substr($language, 0, $position);
3150  if (!in_array($superLanguage, $preferredLanguages)) {
3151  $extendedPreferredLanguages[] = $superLanguage;
3152  }
3153  }
3154  }
3155  $preferredLanguages = array_values(array_intersect($extendedPreferredLanguages, $locales));
3156  return isset($preferredLanguages[0]) ? $preferredLanguages[0] : $locales[0];
3157  }
3158  public function getLanguages()
3159  {
3160  if (null !== $this->languages) {
3161  return $this->languages;
3162  }
3163  $languages = AcceptHeader::fromString($this->headers->get('Accept-Language'))->all();
3164  $this->languages = array();
3165  foreach (array_keys($languages) as $lang) {
3166  if (strstr($lang, '-')) {
3167  $codes = explode('-', $lang);
3168  if ('i' === $codes[0]) {
3169  if (count($codes) > 1) {
3170  $lang = $codes[1];
3171  }
3172  } else {
3173  for ($i = 0, $max = count($codes); $i < $max; $i++) {
3174  if ($i === 0) {
3175  $lang = strtolower($codes[0]);
3176  } else {
3177  $lang .= '_' . strtoupper($codes[$i]);
3178  }
3179  }
3180  }
3181  }
3182  $this->languages[] = $lang;
3183  }
3184  return $this->languages;
3185  }
3186  public function getCharsets()
3187  {
3188  if (null !== $this->charsets) {
3189  return $this->charsets;
3190  }
3191  return $this->charsets = array_keys(AcceptHeader::fromString($this->headers->get('Accept-Charset'))->all());
3192  }
3193  public function getEncodings()
3194  {
3195  if (null !== $this->encodings) {
3196  return $this->encodings;
3197  }
3198  return $this->encodings = array_keys(AcceptHeader::fromString($this->headers->get('Accept-Encoding'))->all());
3199  }
3200  public function getAcceptableContentTypes()
3201  {
3202  if (null !== $this->acceptableContentTypes) {
3203  return $this->acceptableContentTypes;
3204  }
3205  return $this->acceptableContentTypes = array_keys(AcceptHeader::fromString($this->headers->get('Accept'))->all());
3206  }
3207  public function isXmlHttpRequest()
3208  {
3209  return 'XMLHttpRequest' == $this->headers->get('X-Requested-With');
3210  }
3211  protected function prepareRequestUri()
3212  {
3213  $requestUri = '';
3214  if ($this->headers->has('X_ORIGINAL_URL')) {
3215  $requestUri = $this->headers->get('X_ORIGINAL_URL');
3216  $this->headers->remove('X_ORIGINAL_URL');
3217  $this->server->remove('HTTP_X_ORIGINAL_URL');
3218  $this->server->remove('UNENCODED_URL');
3219  $this->server->remove('IIS_WasUrlRewritten');
3220  } elseif ($this->headers->has('X_REWRITE_URL')) {
3221  $requestUri = $this->headers->get('X_REWRITE_URL');
3222  $this->headers->remove('X_REWRITE_URL');
3223  } elseif ($this->server->get('IIS_WasUrlRewritten') == '1' && $this->server->get('UNENCODED_URL') != '') {
3224  $requestUri = $this->server->get('UNENCODED_URL');
3225  $this->server->remove('UNENCODED_URL');
3226  $this->server->remove('IIS_WasUrlRewritten');
3227  } elseif ($this->server->has('REQUEST_URI')) {
3228  $requestUri = $this->server->get('REQUEST_URI');
3229  $schemeAndHttpHost = $this->getSchemeAndHttpHost();
3230  if (strpos($requestUri, $schemeAndHttpHost) === 0) {
3231  $requestUri = substr($requestUri, strlen($schemeAndHttpHost));
3232  }
3233  } elseif ($this->server->has('ORIG_PATH_INFO')) {
3234  $requestUri = $this->server->get('ORIG_PATH_INFO');
3235  if ('' != $this->server->get('QUERY_STRING')) {
3236  $requestUri .= '?' . $this->server->get('QUERY_STRING');
3237  }
3238  $this->server->remove('ORIG_PATH_INFO');
3239  }
3240  $this->server->set('REQUEST_URI', $requestUri);
3241  return $requestUri;
3242  }
3243  protected function prepareBaseUrl()
3244  {
3245  $filename = basename($this->server->get('SCRIPT_FILENAME'));
3246  if (basename($this->server->get('SCRIPT_NAME')) === $filename) {
3247  $baseUrl = $this->server->get('SCRIPT_NAME');
3248  } elseif (basename($this->server->get('PHP_SELF')) === $filename) {
3249  $baseUrl = $this->server->get('PHP_SELF');
3250  } elseif (basename($this->server->get('ORIG_SCRIPT_NAME')) === $filename) {
3251  $baseUrl = $this->server->get('ORIG_SCRIPT_NAME');
3252  } else {
3253  $path = $this->server->get('PHP_SELF', '');
3254  $file = $this->server->get('SCRIPT_FILENAME', '');
3255  $segs = explode('/', trim($file, '/'));
3256  $segs = array_reverse($segs);
3257  $index = 0;
3258  $last = count($segs);
3259  $baseUrl = '';
3260  do {
3261  $seg = $segs[$index];
3262  $baseUrl = '/' . $seg . $baseUrl;
3263  ++$index;
3264  } while ($last > $index && false !== ($pos = strpos($path, $baseUrl)) && 0 != $pos);
3265  }
3266  $requestUri = $this->getRequestUri();
3267  if ($baseUrl && false !== ($prefix = $this->getUrlencodedPrefix($requestUri, $baseUrl))) {
3268  return $prefix;
3269  }
3270  if ($baseUrl && false !== ($prefix = $this->getUrlencodedPrefix($requestUri, dirname($baseUrl) . '/'))) {
3271  return rtrim($prefix, '/');
3272  }
3273  $truncatedRequestUri = $requestUri;
3274  if (false !== ($pos = strpos($requestUri, '?'))) {
3275  $truncatedRequestUri = substr($requestUri, 0, $pos);
3276  }
3277  $basename = basename($baseUrl);
3278  if (empty($basename) || !strpos(rawurldecode($truncatedRequestUri), $basename)) {
3279  return '';
3280  }
3281  if (strlen($requestUri) >= strlen($baseUrl) && false !== ($pos = strpos($requestUri, $baseUrl)) && $pos !== 0) {
3282  $baseUrl = substr($requestUri, 0, $pos + strlen($baseUrl));
3283  }
3284  return rtrim($baseUrl, '/');
3285  }
3286  protected function prepareBasePath()
3287  {
3288  $filename = basename($this->server->get('SCRIPT_FILENAME'));
3289  $baseUrl = $this->getBaseUrl();
3290  if (empty($baseUrl)) {
3291  return '';
3292  }
3293  if (basename($baseUrl) === $filename) {
3294  $basePath = dirname($baseUrl);
3295  } else {
3296  $basePath = $baseUrl;
3297  }
3298  if ('\\' === DIRECTORY_SEPARATOR) {
3299  $basePath = str_replace('\\', '/', $basePath);
3300  }
3301  return rtrim($basePath, '/');
3302  }
3303  protected function preparePathInfo()
3304  {
3305  $baseUrl = $this->getBaseUrl();
3306  if (null === ($requestUri = $this->getRequestUri())) {
3307  return '/';
3308  }
3309  $pathInfo = '/';
3310  if ($pos = strpos($requestUri, '?')) {
3311  $requestUri = substr($requestUri, 0, $pos);
3312  }
3313  if (null !== $baseUrl && false === ($pathInfo = substr($requestUri, strlen($baseUrl)))) {
3314  return '/';
3315  } elseif (null === $baseUrl) {
3316  return $requestUri;
3317  }
3318  return (string) $pathInfo;
3319  }
3320  protected static function initializeFormats()
3321  {
3322  static::$formats = array('html' => array('text/html', 'application/xhtml+xml'), 'txt' => array('text/plain'), 'js' => array('application/javascript', 'application/x-javascript', 'text/javascript'), 'css' => array('text/css'), 'json' => array('application/json', 'application/x-json'), 'xml' => array('text/xml', 'application/xml', 'application/x-xml'), 'rdf' => array('application/rdf+xml'), 'atom' => array('application/atom+xml'), 'rss' => array('application/rss+xml'), 'form' => array('application/x-www-form-urlencoded'));
3323  }
3324  private function setPhpDefaultLocale($locale)
3325  {
3326  try {
3327  if (class_exists('Locale', false)) {
3328  \Locale::setDefault($locale);
3329  }
3330  } catch (\Exception $e) {
3331  }
3332  }
3333  private function getUrlencodedPrefix($string, $prefix)
3334  {
3335  if (0 !== strpos(rawurldecode($string), $prefix)) {
3336  return false;
3337  }
3338  $len = strlen($prefix);
3339  if (preg_match(sprintf('#^(%%[[:xdigit:]]{2}|.){%d}#', $len), $string, $match)) {
3340  return $match[0];
3341  }
3342  return false;
3343  }
3344  private static function createRequestFromFactory(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
3345  {
3346  if (self::$requestFactory) {
3347  $request = call_user_func(self::$requestFactory, $query, $request, $attributes, $cookies, $files, $server, $content);
3348  if (!$request instanceof Request) {
3349  throw new \LogicException('The Request factory must return an instance of Symfony\\Component\\HttpFoundation\\Request.');
3350  }
3351  return $request;
3352  }
3353  return new static($query, $request, $attributes, $cookies, $files, $server, $content);
3354  }
3355  private function isFromTrustedProxy()
3356  {
3357  return self::$trustedProxies && IpUtils::checkIp($this->server->get('REMOTE_ADDR'), self::$trustedProxies);
3358  }
3359 }
3361 
3362 class ParameterBag implements \IteratorAggregate, \Countable
3363 {
3364  protected $parameters;
3365  public function __construct(array $parameters = array())
3366  {
3367  $this->parameters = $parameters;
3368  }
3369  public function all()
3370  {
3371  return $this->parameters;
3372  }
3373  public function keys()
3374  {
3375  return array_keys($this->parameters);
3376  }
3377  public function replace(array $parameters = array())
3378  {
3379  $this->parameters = $parameters;
3380  }
3381  public function add(array $parameters = array())
3382  {
3383  $this->parameters = array_replace($this->parameters, $parameters);
3384  }
3385  public function get($path, $default = null, $deep = false)
3386  {
3387  if (!$deep || false === ($pos = strpos($path, '['))) {
3388  return array_key_exists($path, $this->parameters) ? $this->parameters[$path] : $default;
3389  }
3390  $root = substr($path, 0, $pos);
3391  if (!array_key_exists($root, $this->parameters)) {
3392  return $default;
3393  }
3394  $value = $this->parameters[$root];
3395  $currentKey = null;
3396  for ($i = $pos, $c = strlen($path); $i < $c; $i++) {
3397  $char = $path[$i];
3398  if ('[' === $char) {
3399  if (null !== $currentKey) {
3400  throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "[" at position %d.', $i));
3401  }
3402  $currentKey = '';
3403  } elseif (']' === $char) {
3404  if (null === $currentKey) {
3405  throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "]" at position %d.', $i));
3406  }
3407  if (!is_array($value) || !array_key_exists($currentKey, $value)) {
3408  return $default;
3409  }
3410  $value = $value[$currentKey];
3411  $currentKey = null;
3412  } else {
3413  if (null === $currentKey) {
3414  throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "%s" at position %d.', $char, $i));
3415  }
3416  $currentKey .= $char;
3417  }
3418  }
3419  if (null !== $currentKey) {
3420  throw new \InvalidArgumentException(sprintf('Malformed path. Path must end with "]".'));
3421  }
3422  return $value;
3423  }
3424  public function set($key, $value)
3425  {
3426  $this->parameters[$key] = $value;
3427  }
3428  public function has($key)
3429  {
3430  return array_key_exists($key, $this->parameters);
3431  }
3432  public function remove($key)
3433  {
3434  unset($this->parameters[$key]);
3435  }
3436  public function getAlpha($key, $default = '', $deep = false)
3437  {
3438  return preg_replace('/[^[:alpha:]]/', '', $this->get($key, $default, $deep));
3439  }
3440  public function getAlnum($key, $default = '', $deep = false)
3441  {
3442  return preg_replace('/[^[:alnum:]]/', '', $this->get($key, $default, $deep));
3443  }
3444  public function getDigits($key, $default = '', $deep = false)
3445  {
3446  return str_replace(array('-', '+'), '', $this->filter($key, $default, $deep, FILTER_SANITIZE_NUMBER_INT));
3447  }
3448  public function getInt($key, $default = 0, $deep = false)
3449  {
3450  return (int) $this->get($key, $default, $deep);
3451  }
3452  public function getBoolean($key, $default = false, $deep = false)
3453  {
3454  return $this->filter($key, $default, $deep, FILTER_VALIDATE_BOOLEAN);
3455  }
3456  public function filter($key, $default = null, $deep = false, $filter = FILTER_DEFAULT, $options = array())
3457  {
3458  $value = $this->get($key, $default, $deep);
3459  if (!is_array($options) && $options) {
3460  $options = array('flags' => $options);
3461  }
3462  if (is_array($value) && !isset($options['flags'])) {
3463  $options['flags'] = FILTER_REQUIRE_ARRAY;
3464  }
3465  return filter_var($value, $filter, $options);
3466  }
3467  public function getIterator()
3468  {
3469  return new \ArrayIterator($this->parameters);
3470  }
3471  public function count()
3472  {
3473  return count($this->parameters);
3474  }
3475 }
3477 
3479 class FileBag extends ParameterBag
3480 {
3481  private static $fileKeys = array('error', 'name', 'size', 'tmp_name', 'type');
3482  public function __construct(array $parameters = array())
3483  {
3484  $this->replace($parameters);
3485  }
3486  public function replace(array $files = array())
3487  {
3488  $this->parameters = array();
3489  $this->add($files);
3490  }
3491  public function set($key, $value)
3492  {
3493  if (!is_array($value) && !$value instanceof UploadedFile) {
3494  throw new \InvalidArgumentException('An uploaded file must be an array or an instance of UploadedFile.');
3495  }
3496  parent::set($key, $this->convertFileInformation($value));
3497  }
3498  public function add(array $files = array())
3499  {
3500  foreach ($files as $key => $file) {
3501  $this->set($key, $file);
3502  }
3503  }
3504  protected function convertFileInformation($file)
3505  {
3506  if ($file instanceof UploadedFile) {
3507  return $file;
3508  }
3509  $file = $this->fixPhpFilesArray($file);
3510  if (is_array($file)) {
3511  $keys = array_keys($file);
3512  sort($keys);
3513  if ($keys == self::$fileKeys) {
3514  if (UPLOAD_ERR_NO_FILE == $file['error']) {
3515  $file = null;
3516  } else {
3517  $file = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['size'], $file['error']);
3518  }
3519  } else {
3520  $file = array_map(array($this, 'convertFileInformation'), $file);
3521  }
3522  }
3523  return $file;
3524  }
3525  protected function fixPhpFilesArray($data)
3526  {
3527  if (!is_array($data)) {
3528  return $data;
3529  }
3530  $keys = array_keys($data);
3531  sort($keys);
3532  if (self::$fileKeys != $keys || !isset($data['name']) || !is_array($data['name'])) {
3533  return $data;
3534  }
3535  $files = $data;
3536  foreach (self::$fileKeys as $k) {
3537  unset($files[$k]);
3538  }
3539  foreach ($data['name'] as $key => $name) {
3540  $files[$key] = $this->fixPhpFilesArray(array('error' => $data['error'][$key], 'name' => $name, 'type' => $data['type'][$key], 'tmp_name' => $data['tmp_name'][$key], 'size' => $data['size'][$key]));
3541  }
3542  return $files;
3543  }
3544 }
3546 
3548 {
3549  public function getHeaders()
3550  {
3551  $headers = array();
3552  $contentHeaders = array('CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true);
3553  foreach ($this->parameters as $key => $value) {
3554  if (0 === strpos($key, 'HTTP_')) {
3555  $headers[substr($key, 5)] = $value;
3556  } elseif (isset($contentHeaders[$key])) {
3557  $headers[$key] = $value;
3558  }
3559  }
3560  if (isset($this->parameters['PHP_AUTH_USER'])) {
3561  $headers['PHP_AUTH_USER'] = $this->parameters['PHP_AUTH_USER'];
3562  $headers['PHP_AUTH_PW'] = isset($this->parameters['PHP_AUTH_PW']) ? $this->parameters['PHP_AUTH_PW'] : '';
3563  } else {
3564  $authorizationHeader = null;
3565  if (isset($this->parameters['HTTP_AUTHORIZATION'])) {
3566  $authorizationHeader = $this->parameters['HTTP_AUTHORIZATION'];
3567  } elseif (isset($this->parameters['REDIRECT_HTTP_AUTHORIZATION'])) {
3568  $authorizationHeader = $this->parameters['REDIRECT_HTTP_AUTHORIZATION'];
3569  }
3570  if (null !== $authorizationHeader) {
3571  if (0 === stripos($authorizationHeader, 'basic ')) {
3572  $exploded = explode(':', base64_decode(substr($authorizationHeader, 6)), 2);
3573  if (count($exploded) == 2) {
3574  list($headers['PHP_AUTH_USER'], $headers['PHP_AUTH_PW']) = $exploded;
3575  }
3576  } elseif (empty($this->parameters['PHP_AUTH_DIGEST']) && 0 === stripos($authorizationHeader, 'digest ')) {
3577  $headers['PHP_AUTH_DIGEST'] = $authorizationHeader;
3578  $this->parameters['PHP_AUTH_DIGEST'] = $authorizationHeader;
3579  }
3580  }
3581  }
3582  if (isset($headers['PHP_AUTH_USER'])) {
3583  $headers['AUTHORIZATION'] = 'Basic ' . base64_encode($headers['PHP_AUTH_USER'] . ':' . $headers['PHP_AUTH_PW']);
3584  } elseif (isset($headers['PHP_AUTH_DIGEST'])) {
3585  $headers['AUTHORIZATION'] = $headers['PHP_AUTH_DIGEST'];
3586  }
3587  return $headers;
3588  }
3589 }
3591 
3592 class HeaderBag implements \IteratorAggregate, \Countable
3593 {
3594  protected $headers = array();
3595  protected $cacheControl = array();
3596  public function __construct(array $headers = array())
3597  {
3598  foreach ($headers as $key => $values) {
3599  $this->set($key, $values);
3600  }
3601  }
3602  public function __toString()
3603  {
3604  if (!$this->headers) {
3605  return '';
3606  }
3607  $max = max(array_map('strlen', array_keys($this->headers))) + 1;
3608  $content = '';
3609  ksort($this->headers);
3610  foreach ($this->headers as $name => $values) {
3611  $name = implode('-', array_map('ucfirst', explode('-', $name)));
3612  foreach ($values as $value) {
3613  $content .= sprintf("%-{$max}s %s\r\n", $name . ':', $value);
3614  }
3615  }
3616  return $content;
3617  }
3618  public function all()
3619  {
3620  return $this->headers;
3621  }
3622  public function keys()
3623  {
3624  return array_keys($this->headers);
3625  }
3626  public function replace(array $headers = array())
3627  {
3628  $this->headers = array();
3629  $this->add($headers);
3630  }
3631  public function add(array $headers)
3632  {
3633  foreach ($headers as $key => $values) {
3634  $this->set($key, $values);
3635  }
3636  }
3637  public function get($key, $default = null, $first = true)
3638  {
3639  $key = strtr(strtolower($key), '_', '-');
3640  if (!array_key_exists($key, $this->headers)) {
3641  if (null === $default) {
3642  return $first ? null : array();
3643  }
3644  return $first ? $default : array($default);
3645  }
3646  if ($first) {
3647  return count($this->headers[$key]) ? $this->headers[$key][0] : $default;
3648  }
3649  return $this->headers[$key];
3650  }
3651  public function set($key, $values, $replace = true)
3652  {
3653  $key = strtr(strtolower($key), '_', '-');
3654  $values = array_values((array) $values);
3655  if (true === $replace || !isset($this->headers[$key])) {
3656  $this->headers[$key] = $values;
3657  } else {
3658  $this->headers[$key] = array_merge($this->headers[$key], $values);
3659  }
3660  if ('cache-control' === $key) {
3661  $this->cacheControl = $this->parseCacheControl($values[0]);
3662  }
3663  }
3664  public function has($key)
3665  {
3666  return array_key_exists(strtr(strtolower($key), '_', '-'), $this->headers);
3667  }
3668  public function contains($key, $value)
3669  {
3670  return in_array($value, $this->get($key, null, false));
3671  }
3672  public function remove($key)
3673  {
3674  $key = strtr(strtolower($key), '_', '-');
3675  unset($this->headers[$key]);
3676  if ('cache-control' === $key) {
3677  $this->cacheControl = array();
3678  }
3679  }
3680  public function getDate($key, \DateTime $default = null)
3681  {
3682  if (null === ($value = $this->get($key))) {
3683  return $default;
3684  }
3685  if (false === ($date = \DateTime::createFromFormat(DATE_RFC2822, $value))) {
3686  throw new \RuntimeException(sprintf('The %s HTTP header is not parseable (%s).', $key, $value));
3687  }
3688  return $date;
3689  }
3690  public function addCacheControlDirective($key, $value = true)
3691  {
3692  $this->cacheControl[$key] = $value;
3693  $this->set('Cache-Control', $this->getCacheControlHeader());
3694  }
3695  public function hasCacheControlDirective($key)
3696  {
3697  return array_key_exists($key, $this->cacheControl);
3698  }
3699  public function getCacheControlDirective($key)
3700  {
3701  return array_key_exists($key, $this->cacheControl) ? $this->cacheControl[$key] : null;
3702  }
3703  public function removeCacheControlDirective($key)
3704  {
3705  unset($this->cacheControl[$key]);
3706  $this->set('Cache-Control', $this->getCacheControlHeader());
3707  }
3708  public function getIterator()
3709  {
3710  return new \ArrayIterator($this->headers);
3711  }
3712  public function count()
3713  {
3714  return count($this->headers);
3715  }
3716  protected function getCacheControlHeader()
3717  {
3718  $parts = array();
3719  ksort($this->cacheControl);
3720  foreach ($this->cacheControl as $key => $value) {
3721  if (true === $value) {
3722  $parts[] = $key;
3723  } else {
3724  if (preg_match('#[^a-zA-Z0-9._-]#', $value)) {
3725  $value = '"' . $value . '"';
3726  }
3727  $parts[] = "{$key}={$value}";
3728  }
3729  }
3730  return implode(', ', $parts);
3731  }
3732  protected function parseCacheControl($header)
3733  {
3734  $cacheControl = array();
3735  preg_match_all('#([a-zA-Z][a-zA-Z_-]*)\\s*(?:=(?:"([^"]*)"|([^ \\t",;]*)))?#', $header, $matches, PREG_SET_ORDER);
3736  foreach ($matches as $match) {
3737  $cacheControl[strtolower($match[1])] = isset($match[3]) ? $match[3] : (isset($match[2]) ? $match[2] : true);
3738  }
3739  return $cacheControl;
3740  }
3741 }
3743 
3746 {
3747  public function start();
3748  public function getId();
3749  public function setId($id);
3750  public function getName();
3751  public function setName($name);
3752  public function invalidate($lifetime = null);
3753  public function migrate($destroy = false, $lifetime = null);
3754  public function save();
3755  public function has($name);
3756  public function get($name, $default = null);
3757  public function set($name, $value);
3758  public function all();
3759  public function replace(array $attributes);
3760  public function remove($name);
3761  public function clear();
3762  public function isStarted();
3763  public function registerBag(SessionBagInterface $bag);
3764  public function getBag($name);
3765  public function getMetadataBag();
3766 }
3768 
3770 {
3771  public function getName();
3772  public function initialize(array &$array);
3773  public function getStorageKey();
3774  public function clear();
3775 }
3777 
3780 {
3781  public function has($name);
3782  public function get($name, $default = null);
3783  public function set($name, $value);
3784  public function all();
3785  public function replace(array $attributes);
3786  public function remove($name);
3787 }
3789 
3790 class AttributeBag implements AttributeBagInterface, \IteratorAggregate, \Countable
3791 {
3792  private $name = 'attributes';
3793  private $storageKey;
3794  protected $attributes = array();
3795  public function __construct($storageKey = '_sf2_attributes')
3796  {
3797  $this->storageKey = $storageKey;
3798  }
3799  public function getName()
3800  {
3801  return $this->name;
3802  }
3803  public function setName($name)
3804  {
3805  $this->name = $name;
3806  }
3807  public function initialize(array &$attributes)
3808  {
3809  $this->attributes =& $attributes;
3810  }
3811  public function getStorageKey()
3812  {
3813  return $this->storageKey;
3814  }
3815  public function has($name)
3816  {
3817  return array_key_exists($name, $this->attributes);
3818  }
3819  public function get($name, $default = null)
3820  {
3821  return array_key_exists($name, $this->attributes) ? $this->attributes[$name] : $default;
3822  }
3823  public function set($name, $value)
3824  {
3825  $this->attributes[$name] = $value;
3826  }
3827  public function all()
3828  {
3829  return $this->attributes;
3830  }
3831  public function replace(array $attributes)
3832  {
3833  $this->attributes = array();
3834  foreach ($attributes as $key => $value) {
3835  $this->set($key, $value);
3836  }
3837  }
3838  public function remove($name)
3839  {
3840  $retval = null;
3841  if (array_key_exists($name, $this->attributes)) {
3842  $retval = $this->attributes[$name];
3843  unset($this->attributes[$name]);
3844  }
3845  return $retval;
3846  }
3847  public function clear()
3848  {
3849  $return = $this->attributes;
3850  $this->attributes = array();
3851  return $return;
3852  }
3853  public function getIterator()
3854  {
3855  return new \ArrayIterator($this->attributes);
3856  }
3857  public function count()
3858  {
3859  return count($this->attributes);
3860  }
3861 }
3863 
3866 {
3867  const CREATED = 'c';
3868  const UPDATED = 'u';
3869  const LIFETIME = 'l';
3870  private $name = '__metadata';
3871  private $storageKey;
3872  protected $meta = array(self::CREATED => 0, self::UPDATED => 0, self::LIFETIME => 0);
3873  private $lastUsed;
3874  private $updateThreshold;
3875  public function __construct($storageKey = '_sf2_meta', $updateThreshold = 0)
3876  {
3877  $this->storageKey = $storageKey;
3878  $this->updateThreshold = $updateThreshold;
3879  }
3880  public function initialize(array &$array)
3881  {
3882  $this->meta =& $array;
3883  if (isset($array[self::CREATED])) {
3884  $this->lastUsed = $this->meta[self::UPDATED];
3885  $timeStamp = time();
3886  if ($timeStamp - $array[self::UPDATED] >= $this->updateThreshold) {
3887  $this->meta[self::UPDATED] = $timeStamp;
3888  }
3889  } else {
3890  $this->stampCreated();
3891  }
3892  }
3893  public function getLifetime()
3894  {
3895  return $this->meta[self::LIFETIME];
3896  }
3897  public function stampNew($lifetime = null)
3898  {
3899  $this->stampCreated($lifetime);
3900  }
3901  public function getStorageKey()
3902  {
3903  return $this->storageKey;
3904  }
3905  public function getCreated()
3906  {
3907  return $this->meta[self::CREATED];
3908  }
3909  public function getLastUsed()
3910  {
3911  return $this->lastUsed;
3912  }
3913  public function clear()
3914  {
3915  }
3916  public function getName()
3917  {
3918  return $this->name;
3919  }
3920  public function setName($name)
3921  {
3922  $this->name = $name;
3923  }
3924  private function stampCreated($lifetime = null)
3925  {
3926  $timeStamp = time();
3927  $this->meta[self::CREATED] = $this->meta[self::UPDATED] = $this->lastUsed = $timeStamp;
3928  $this->meta[self::LIFETIME] = null === $lifetime ? ini_get('session.cookie_lifetime') : $lifetime;
3929  }
3930 }
3932 
3934 {
3935  private $value;
3936  private $quality = 1.0;
3937  private $index = 0;
3938  private $attributes = array();
3939  public function __construct($value, array $attributes = array())
3940  {
3941  $this->value = $value;
3942  foreach ($attributes as $name => $value) {
3943  $this->setAttribute($name, $value);
3944  }
3945  }
3946  public static function fromString($itemValue)
3947  {
3948  $bits = preg_split('/\\s*(?:;*("[^"]+");*|;*(\'[^\']+\');*|;+)\\s*/', $itemValue, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
3949  $value = array_shift($bits);
3950  $attributes = array();
3951  $lastNullAttribute = null;
3952  foreach ($bits as $bit) {
3953  if (($start = substr($bit, 0, 1)) === ($end = substr($bit, -1)) && ($start === '"' || $start === '\'')) {
3954  $attributes[$lastNullAttribute] = substr($bit, 1, -1);
3955  } elseif ('=' === $end) {
3956  $lastNullAttribute = $bit = substr($bit, 0, -1);
3957  $attributes[$bit] = null;
3958  } else {
3959  $parts = explode('=', $bit);
3960  $attributes[$parts[0]] = isset($parts[1]) && strlen($parts[1]) > 0 ? $parts[1] : '';
3961  }
3962  }
3963  return new self(($start = substr($value, 0, 1)) === ($end = substr($value, -1)) && ($start === '"' || $start === '\'') ? substr($value, 1, -1) : $value, $attributes);
3964  }
3965  public function __toString()
3966  {
3967  $string = $this->value . ($this->quality < 1 ? ';q=' . $this->quality : '');
3968  if (count($this->attributes) > 0) {
3969  $string .= ';' . implode(';', array_map(function ($name, $value) {
3970  return sprintf(preg_match('/[,;=]/', $value) ? '%s="%s"' : '%s=%s', $name, $value);
3971  }, array_keys($this->attributes), $this->attributes));
3972  }
3973  return $string;
3974  }
3975  public function setValue($value)
3976  {
3977  $this->value = $value;
3978  return $this;
3979  }
3980  public function getValue()
3981  {
3982  return $this->value;
3983  }
3984  public function setQuality($quality)
3985  {
3986  $this->quality = $quality;
3987  return $this;
3988  }
3989  public function getQuality()
3990  {
3991  return $this->quality;
3992  }
3993  public function setIndex($index)
3994  {
3995  $this->index = $index;
3996  return $this;
3997  }
3998  public function getIndex()
3999  {
4000  return $this->index;
4001  }
4002  public function hasAttribute($name)
4003  {
4004  return isset($this->attributes[$name]);
4005  }
4006  public function getAttribute($name, $default = null)
4007  {
4008  return isset($this->attributes[$name]) ? $this->attributes[$name] : $default;
4009  }
4010  public function getAttributes()
4011  {
4012  return $this->attributes;
4013  }
4014  public function setAttribute($name, $value)
4015  {
4016  if ('q' === $name) {
4017  $this->quality = (double) $value;
4018  } else {
4019  $this->attributes[$name] = (string) $value;
4020  }
4021  return $this;
4022  }
4023 }
4025 
4027 {
4028  private $items = array();
4029  private $sorted = true;
4030  public function __construct(array $items)
4031  {
4032  foreach ($items as $item) {
4033  $this->add($item);
4034  }
4035  }
4036  public static function fromString($headerValue)
4037  {
4038  $index = 0;
4039  return new self(array_map(function ($itemValue) use(&$index) {
4040  $item = AcceptHeaderItem::fromString($itemValue);
4041  $item->setIndex($index++);
4042  return $item;
4043  }, preg_split('/\\s*(?:,*("[^"]+"),*|,*(\'[^\']+\'),*|,+)\\s*/', $headerValue, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE)));
4044  }
4045  public function __toString()
4046  {
4047  return implode(',', $this->items);
4048  }
4049  public function has($value)
4050  {
4051  return isset($this->items[$value]);
4052  }
4053  public function get($value)
4054  {
4055  return isset($this->items[$value]) ? $this->items[$value] : null;
4056  }
4057  public function add(AcceptHeaderItem $item)
4058  {
4059  $this->items[$item->getValue()] = $item;
4060  $this->sorted = false;
4061  return $this;
4062  }
4063  public function all()
4064  {
4065  $this->sort();
4066  return $this->items;
4067  }
4068  public function filter($pattern)
4069  {
4070  return new self(array_filter($this->items, function (AcceptHeaderItem $item) use($pattern) {
4071  return preg_match($pattern, $item->getValue());
4072  }));
4073  }
4074  public function first()
4075  {
4076  $this->sort();
4077  return !empty($this->items) ? reset($this->items) : null;
4078  }
4079  private function sort()
4080  {
4081  if (!$this->sorted) {
4082  uasort($this->items, function ($a, $b) {
4083  $qA = $a->getQuality();
4084  $qB = $b->getQuality();
4085  if ($qA === $qB) {
4086  return $a->getIndex() > $b->getIndex() ? 1 : -1;
4087  }
4088  return $qA > $qB ? -1 : 1;
4089  });
4090  $this->sorted = true;
4091  }
4092  }
4093 }
4095 
4100 {
4101  private $debug;
4102  private $charset;
4103  private $handler;
4104  private $caughtBuffer;
4105  private $caughtLength;
4106  private $fileLinkFormat;
4107  public function __construct($debug = true, $charset = null, $fileLinkFormat = null)
4108  {
4109  if (false !== strpos($charset, '%') xor false === strpos($fileLinkFormat, '%')) {
4110  $pivot = $fileLinkFormat;
4111  $fileLinkFormat = $charset;
4112  $charset = $pivot;
4113  }
4114  $this->debug = $debug;
4115  $this->charset = $charset ?: ini_get('default_charset') ?: 'UTF-8';
4116  $this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
4117  }
4118  public static function register($debug = true, $charset = null, $fileLinkFormat = null)
4119  {
4120  $handler = new static($debug, $charset, $fileLinkFormat);
4121  $prev = set_exception_handler(array($handler, 'handle'));
4122  if (is_array($prev) && $prev[0] instanceof ErrorHandler) {
4123  restore_exception_handler();
4124  $prev[0]->setExceptionHandler(array($handler, 'handle'));
4125  }
4126  return $handler;
4127  }
4128  public function setHandler($handler)
4129  {
4130  if (null !== $handler && !is_callable($handler)) {
4131  throw new \LogicException('The exception handler must be a valid PHP callable.');
4132  }
4133  $old = $this->handler;
4134  $this->handler = $handler;
4135  return $old;
4136  }
4137  public function setFileLinkFormat($format)
4138  {
4139  $old = $this->fileLinkFormat;
4140  $this->fileLinkFormat = $format;
4141  return $old;
4142  }
4143  public function handle(\Exception $exception)
4144  {
4145  if (null === $this->handler || $exception instanceof OutOfMemoryException) {
4146  $this->failSafeHandle($exception);
4147  return;
4148  }
4149  $caughtLength = $this->caughtLength = 0;
4150  ob_start(array($this, 'catchOutput'));
4151  $this->failSafeHandle($exception);
4152  while (null === $this->caughtBuffer && ob_end_flush()) {
4153  }
4154  if (isset($this->caughtBuffer[0])) {
4155  ob_start(array($this, 'cleanOutput'));
4156  echo $this->caughtBuffer;
4157  $caughtLength = ob_get_length();
4158  }
4159  $this->caughtBuffer = null;
4160  try {
4161  call_user_func($this->handler, $exception);
4162  $this->caughtLength = $caughtLength;
4163  } catch (\Exception $e) {
4164  if (!$caughtLength) {
4165  throw $exception;
4166  }
4167  }
4168  }
4169  private function failSafeHandle(\Exception $exception)
4170  {
4171  if (class_exists('Symfony\\Component\\HttpFoundation\\Response', false)) {
4172  $response = $this->createResponse($exception);
4173  $response->sendHeaders();
4174  $response->sendContent();
4175  } else {
4176  $this->sendPhpResponse($exception);
4177  }
4178  }
4179  public function sendPhpResponse($exception)
4180  {
4181  if (!$exception instanceof FlattenException) {
4182  $exception = FlattenException::create($exception);
4183  }
4184  if (!headers_sent()) {
4185  header(sprintf('HTTP/1.0 %s', $exception->getStatusCode()));
4186  foreach ($exception->getHeaders() as $name => $value) {
4187  header($name . ': ' . $value, false);
4188  }
4189  header('Content-Type: text/html; charset=' . $this->charset);
4190  }
4191  echo $this->decorate($this->getContent($exception), $this->getStylesheet($exception));
4192  }
4193  public function createResponse($exception)
4194  {
4195  if (!$exception instanceof FlattenException) {
4196  $exception = FlattenException::create($exception);
4197  }
4198  return Response::create($this->decorate($this->getContent($exception), $this->getStylesheet($exception)), $exception->getStatusCode(), $exception->getHeaders())->setCharset($this->charset);
4199  }
4200  public function getContent(FlattenException $exception)
4201  {
4202  switch ($exception->getStatusCode()) {
4203  case 404:
4204  $title = 'Sorry, the page you are looking for could not be found.';
4205  break;
4206  default:
4207  $title = 'Whoops, looks like something went wrong.';
4208  }
4209  $content = '';
4210  if ($this->debug) {
4211  try {
4212  $count = count($exception->getAllPrevious());
4213  $total = $count + 1;
4214  foreach ($exception->toArray() as $position => $e) {
4215  $ind = $count - $position + 1;
4216  $class = $this->formatClass($e['class']);
4217  $message = nl2br($this->escapeHtml($e['message']));
4218  $content .= sprintf(' <h2 class="block_exception clear_fix">
4219  <span class="exception_counter">%d/%d</span>
4220  <span class="exception_title">%s%s:</span>
4221  <span class="exception_message">%s</span>
4222  </h2>
4223  <div class="block">
4224  <ol class="traces list_exception">', $ind, $total, $class, $this->formatPath($e['trace'][0]['file'], $e['trace'][0]['line']), $message);
4225  foreach ($e['trace'] as $trace) {
4226  $content .= ' <li>';
4227  if ($trace['function']) {
4228  $content .= sprintf('at %s%s%s(%s)', $this->formatClass($trace['class']), $trace['type'], $trace['function'], $this->formatArgs($trace['args']));
4229  }
4230  if (isset($trace['file']) && isset($trace['line'])) {
4231  $content .= $this->formatPath($trace['file'], $trace['line']);
4232  }
4233  $content .= '</li>
4234 ';
4235  }
4236  $content .= ' </ol>
4237 </div>
4238 ';
4239  }
4240  } catch (\Exception $e) {
4241  if ($this->debug) {
4242  $title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $this->escapeHtml($e->getMessage()));
4243  } else {
4244  $title = 'Whoops, looks like something went wrong.';
4245  }
4246  }
4247  }
4248  return " <div id=\"sf-resetcontent\" class=\"sf-reset\">\n <h1>{$title}</h1>\n {$content}\n </div>";
4249  }
4250  public function getStylesheet(FlattenException $exception)
4251  {
4252  return ' .sf-reset { font: 11px Verdana, Arial, sans-serif; color: #333 }
4253  .sf-reset .clear { clear:both; height:0; font-size:0; line-height:0; }
4254  .sf-reset .clear_fix:after { display:block; height:0; clear:both; visibility:hidden; }
4255  .sf-reset .clear_fix { display:inline-block; }
4256  .sf-reset * html .clear_fix { height:1%; }
4257  .sf-reset .clear_fix { display:block; }
4258  .sf-reset, .sf-reset .block { margin: auto }
4259  .sf-reset abbr { border-bottom: 1px dotted #000; cursor: help; }
4260  .sf-reset p { font-size:14px; line-height:20px; color:#868686; padding-bottom:20px }
4261  .sf-reset strong { font-weight:bold; }
4262  .sf-reset a { color:#6c6159; cursor: default; }
4263  .sf-reset a img { border:none; }
4264  .sf-reset a:hover { text-decoration:underline; }
4265  .sf-reset em { font-style:italic; }
4266  .sf-reset h1, .sf-reset h2 { font: 20px Georgia, "Times New Roman", Times, serif }
4267  .sf-reset .exception_counter { background-color: #fff; color: #333; padding: 6px; float: left; margin-right: 10px; float: left; display: block; }
4268  .sf-reset .exception_title { margin-left: 3em; margin-bottom: 0.7em; display: block; }
4269  .sf-reset .exception_message { margin-left: 3em; display: block; }
4270  .sf-reset .traces li { font-size:12px; padding: 2px 4px; list-style-type:decimal; margin-left:20px; }
4271  .sf-reset .block { background-color:#FFFFFF; padding:10px 28px; margin-bottom:20px;
4272  -webkit-border-bottom-right-radius: 16px;
4273  -webkit-border-bottom-left-radius: 16px;
4274  -moz-border-radius-bottomright: 16px;
4275  -moz-border-radius-bottomleft: 16px;
4276  border-bottom-right-radius: 16px;
4277  border-bottom-left-radius: 16px;
4278  border-bottom:1px solid #ccc;
4279  border-right:1px solid #ccc;
4280  border-left:1px solid #ccc;
4281  }
4282  .sf-reset .block_exception { background-color:#ddd; color: #333; padding:20px;
4283  -webkit-border-top-left-radius: 16px;
4284  -webkit-border-top-right-radius: 16px;
4285  -moz-border-radius-topleft: 16px;
4286  -moz-border-radius-topright: 16px;
4287  border-top-left-radius: 16px;
4288  border-top-right-radius: 16px;
4289  border-top:1px solid #ccc;
4290  border-right:1px solid #ccc;
4291  border-left:1px solid #ccc;
4292  overflow: hidden;
4293  word-wrap: break-word;
4294  }
4295  .sf-reset a { background:none; color:#868686; text-decoration:none; }
4296  .sf-reset a:hover { background:none; color:#313131; text-decoration:underline; }
4297  .sf-reset ol { padding: 10px 0; }
4298  .sf-reset h1 { background-color:#FFFFFF; padding: 15px 28px; margin-bottom: 20px;
4299  -webkit-border-radius: 10px;
4300  -moz-border-radius: 10px;
4301  border-radius: 10px;
4302  border: 1px solid #ccc;
4303  }';
4304  }
4305  private function decorate($content, $css)
4306  {
4307  return "<!DOCTYPE html>\n<html>\n <head>\n <meta charset=\"{$this->charset}\" />\n <meta name=\"robots\" content=\"noindex,nofollow\" />\n <style>\n /* Copyright (c) 2010, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.com/yui/license.html */\n html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}li{list-style:none;}caption,th{text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym{border:0;font-variant:normal;}sup{vertical-align:text-top;}sub{vertical-align:text-bottom;}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;}input,textarea,select{*font-size:100%;}legend{color:#000;}\n\n html { background: #eee; padding: 10px }\n img { border: 0; }\n #sf-resetcontent { width:970px; margin:0 auto; }\n {$css}\n </style>\n </head>\n <body>\n {$content}\n </body>\n</html>";
4308  }
4309  private function formatClass($class)
4310  {
4311  $parts = explode('\\', $class);
4312  return sprintf('<abbr title="%s">%s</abbr>', $class, array_pop($parts));
4313  }
4314  private function formatPath($path, $line)
4315  {
4316  $path = $this->escapeHtml($path);
4317  $file = preg_match('#[^/\\\\]*$#', $path, $file) ? $file[0] : $path;
4318  if ($linkFormat = $this->fileLinkFormat) {
4319  $link = str_replace(array('%f', '%l'), array($path, $line), $linkFormat);
4320  return sprintf(' in <a href="%s" title="Go to source">%s line %d</a>', $link, $file, $line);
4321  }
4322  return sprintf(' in <a title="%s line %3$d" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">%s line %d</a>', $path, $file, $line);
4323  }
4324  private function formatArgs(array $args)
4325  {
4326  $result = array();
4327  foreach ($args as $key => $item) {
4328  if ('object' === $item[0]) {
4329  $formattedValue = sprintf('<em>object</em>(%s)', $this->formatClass($item[1]));
4330  } elseif ('array' === $item[0]) {
4331  $formattedValue = sprintf('<em>array</em>(%s)', is_array($item[1]) ? $this->formatArgs($item[1]) : $item[1]);
4332  } elseif ('string' === $item[0]) {
4333  $formattedValue = sprintf('\'%s\'', $this->escapeHtml($item[1]));
4334  } elseif ('null' === $item[0]) {
4335  $formattedValue = '<em>null</em>';
4336  } elseif ('boolean' === $item[0]) {
4337  $formattedValue = '<em>' . strtolower(var_export($item[1], true)) . '</em>';
4338  } elseif ('resource' === $item[0]) {
4339  $formattedValue = '<em>resource</em>';
4340  } else {
4341  $formattedValue = str_replace('
4342 ', '', var_export($this->escapeHtml((string) $item[1]), true));
4343  }
4344  $result[] = is_int($key) ? $formattedValue : sprintf('\'%s\' => %s', $key, $formattedValue);
4345  }
4346  return implode(', ', $result);
4347  }
4348  protected static function utf8Htmlize($str)
4349  {
4350  if (!preg_match('//u', $str) && function_exists('iconv')) {
4351  set_error_handler('var_dump', 0);
4352  $charset = ini_get('default_charset');
4353  if ('UTF-8' === $charset || $str !== @iconv($charset, $charset, $str)) {
4354  $charset = 'CP1252';
4355  }
4356  restore_error_handler();
4357  $str = iconv($charset, 'UTF-8', $str);
4358  }
4359  return htmlspecialchars($str, ENT_QUOTES | (PHP_VERSION_ID >= 50400 ? ENT_SUBSTITUTE : 0), 'UTF-8');
4360  }
4361  private function escapeHtml($str)
4362  {
4363  return htmlspecialchars($str, ENT_QUOTES | (PHP_VERSION_ID >= 50400 ? ENT_SUBSTITUTE : 0), $this->charset);
4364  }
4365  public function catchOutput($buffer)
4366  {
4367  $this->caughtBuffer = $buffer;
4368  return '';
4369  }
4370  public function cleanOutput($buffer)
4371  {
4372  if ($this->caughtLength) {
4373  $cleanBuffer = substr_replace($buffer, '', 0, $this->caughtLength);
4374  if (isset($cleanBuffer[0])) {
4375  $buffer = $cleanBuffer;
4376  }
4377  }
4378  return $buffer;
4379  }
4380 }
4382 
4384 abstract class ServiceProvider
4385 {
4386  protected $app;
4387  protected $defer = false;
4388  protected static $publishes = array();
4389  protected static $publishGroups = array();
4390  public function __construct($app)
4391  {
4392  $this->app = $app;
4393  }
4394  public abstract function register();
4395  protected function mergeConfigFrom($path, $key)
4396  {
4397  $config = $this->app['config']->get($key, array());
4398  $this->app['config']->set($key, array_merge(require $path, $config));
4399  }
4400  protected function loadViewsFrom($path, $namespace)
4401  {
4402  if (is_dir($appPath = $this->app->basePath() . '/resources/views/vendor/' . $namespace)) {
4403  $this->app['view']->addNamespace($namespace, $appPath);
4404  }
4405  $this->app['view']->addNamespace($namespace, $path);
4406  }
4407  protected function loadTranslationsFrom($path, $namespace)
4408  {
4409  $this->app['translator']->addNamespace($namespace, $path);
4410  }
4411  protected function publishes(array $paths, $group = null)
4412  {
4413  $class = get_class($this);
4414  if (!array_key_exists($class, static::$publishes)) {
4415  static::$publishes[$class] = array();
4416  }
4417  static::$publishes[$class] = array_merge(static::$publishes[$class], $paths);
4418  if ($group) {
4419  static::$publishGroups[$group] = $paths;
4420  }
4421  }
4422  public static function pathsToPublish($provider = null, $group = null)
4423  {
4424  if ($group && array_key_exists($group, static::$publishGroups)) {
4425  return static::$publishGroups[$group];
4426  }
4427  if ($provider && array_key_exists($provider, static::$publishes)) {
4428  return static::$publishes[$provider];
4429  }
4430  if ($group || $provider) {
4431  return array();
4432  }
4433  $paths = array();
4434  foreach (static::$publishes as $class => $publish) {
4435  $paths = array_merge($paths, $publish);
4436  }
4437  return $paths;
4438  }
4439  public function commands($commands)
4440  {
4441  $commands = is_array($commands) ? $commands : func_get_args();
4442  $events = $this->app['events'];
4443  $events->listen('artisan.start', function ($artisan) use($commands) {
4444  $artisan->resolveCommands($commands);
4445  });
4446  }
4447  public function provides()
4448  {
4449  return array();
4450  }
4451  public function when()
4452  {
4453  return array();
4454  }
4455  public function isDeferred()
4456  {
4457  return $this->defer;
4458  }
4459  public static function compiles()
4460  {
4461  return array();
4462  }
4463  public function __call($method, $parameters)
4464  {
4465  if ($method == 'boot') {
4466  return;
4467  }
4468  throw new BadMethodCallException("Call to undefined method [{$method}]");
4469  }
4470 }
4471 namespace Illuminate\Support;
4472 
4474 {
4475  protected $providers = array();
4476  protected $instances = array();
4477  public function register()
4478  {
4479  $this->instances = array();
4480  foreach ($this->providers as $provider) {
4481  $this->instances[] = $this->app->register($provider);
4482  }
4483  }
4484  public function provides()
4485  {
4486  $provides = array();
4487  foreach ($this->providers as $provider) {
4488  $instance = $this->app->resolveProviderClass($provider);
4489  $provides = array_merge($provides, $instance->provides());
4490  }
4491  return $provides;
4492  }
4493 }
4495 
4498 {
4499  public function register()
4500  {
4501  $this->registerRouter();
4502  $this->registerUrlGenerator();
4503  $this->registerRedirector();
4504  $this->registerResponseFactory();
4505  }
4506  protected function registerRouter()
4507  {
4508  $this->app['router'] = $this->app->share(function ($app) {
4509  return new Router($app['events'], $app);
4510  });
4511  }
4512  protected function registerUrlGenerator()
4513  {
4514  $this->app['url'] = $this->app->share(function ($app) {
4515  $routes = $app['router']->getRoutes();
4516  $app->instance('routes', $routes);
4517  $url = new UrlGenerator($routes, $app->rebinding('request', $this->requestRebinder()));
4518  $url->setSessionResolver(function () {
4519  return $this->app['session'];
4520  });
4521  $app->rebinding('routes', function ($app, $routes) {
4522  $app['url']->setRoutes($routes);
4523  });
4524  return $url;
4525  });
4526  }
4527  protected function requestRebinder()
4528  {
4529  return function ($app, $request) {
4530  $app['url']->setRequest($request);
4531  };
4532  }
4533  protected function registerRedirector()
4534  {
4535  $this->app['redirect'] = $this->app->share(function ($app) {
4536  $redirector = new Redirector($app['url']);
4537  if (isset($app['session.store'])) {
4538  $redirector->setSession($app['session.store']);
4539  }
4540  return $redirector;
4541  });
4542  }
4543  protected function registerResponseFactory()
4544  {
4545  $this->app->singleton('Illuminate\\Contracts\\Routing\\ResponseFactory', function ($app) {
4546  return new ResponseFactory($app['Illuminate\\Contracts\\View\\Factory'], $app['redirect']);
4547  });
4548  }
4549 }
4550 namespace Illuminate\Routing;
4551 
4554 {
4555  public function register()
4556  {
4557  $this->app->singleton('illuminate.route.dispatcher', function ($app) {
4558  return new ControllerDispatcher($app['router'], $app);
4559  });
4560  }
4561 }
4563 
4566 {
4567  public function register()
4568  {
4569  $this->app->singleton('events', function ($app) {
4570  return (new Dispatcher($app))->setQueueResolver(function () use($app) {
4571  return $app->make('Illuminate\\Contracts\\Queue\\Queue');
4572  });
4573  });
4574  }
4575 }
4577 
4581 {
4582  public function register()
4583  {
4584  $this->registerValidationResolverHook();
4585  $this->registerPresenceVerifier();
4586  $this->registerValidationFactory();
4587  }
4588  protected function registerValidationResolverHook()
4589  {
4590  $this->app->afterResolving(function (ValidatesWhenResolved $resolved) {
4591  $resolved->validate();
4592  });
4593  }
4594  protected function registerValidationFactory()
4595  {
4596  $this->app->singleton('validator', function ($app) {
4597  $validator = new Factory($app['translator'], $app);
4598  if (isset($app['validation.presence'])) {
4599  $validator->setPresenceVerifier($app['validation.presence']);
4600  }
4601  return $validator;
4602  });
4603  }
4604  protected function registerPresenceVerifier()
4605  {
4606  $this->app->singleton('validation.presence', function ($app) {
4607  return new DatabasePresenceVerifier($app['db']);
4608  });
4609  }
4610 }
4612 
4617 trait ValidatesRequests
4619  public function validate(Request $request, array $rules, array $messages = array())
4620  {
4621  $validator = $this->getValidationFactory()->make($request->all(), $rules, $messages);
4622  if ($validator->fails()) {
4623  $this->throwValidationException($request, $validator);
4624  }
4625  }
4626  protected function throwValidationException(Request $request, $validator)
4627  {
4628  throw new HttpResponseException($this->buildFailedValidationResponse($request, $this->formatValidationErrors($validator)));
4629  }
4630  protected function buildFailedValidationResponse(Request $request, array $errors)
4631  {
4632  if ($request->ajax() || $request->wantsJson()) {
4633  return new JsonResponse($errors, 422);
4634  }
4635  return redirect()->to($this->getRedirectUrl())->withInput($request->input())->withErrors($errors, $this->errorBag());
4636  }
4637  protected function formatValidationErrors(Validator $validator)
4638  {
4639  return $validator->errors()->getMessages();
4640  }
4641  protected function getRedirectUrl()
4642  {
4643  return app('Illuminate\\Routing\\UrlGenerator')->previous();
4644  }
4645  protected function getValidationFactory()
4646  {
4647  return app('Illuminate\\Contracts\\Validation\\Factory');
4648  }
4649  protected function errorBag()
4650  {
4651  return 'default';
4652  }
4653 }
4654 namespace Illuminate\Validation;
4655 
4660  public function validate()
4661  {
4662  $instance = $this->getValidatorInstance();
4663  if (!$this->passesAuthorization()) {
4664  $this->failedAuthorization();
4665  } elseif (!$instance->passes()) {
4666  $this->failedValidation($instance);
4667  }
4668  }
4669  protected function getValidatorInstance()
4670  {
4671  return $this->validator();
4672  }
4673  protected function failedValidation(Validator $validator)
4674  {
4675  throw new ValidationException($validator);
4676  }
4677  protected function passesAuthorization()
4678  {
4679  if (method_exists($this, 'authorize')) {
4680  return $this->authorize();
4681  }
4682  return true;
4683  }
4684  protected function failedAuthorization()
4685  {
4686  throw new UnauthorizedException();
4687  }
4688 }
4689 namespace Illuminate\Foundation\Http;
4690 
4701 {
4703  protected $container;
4704  protected $redirector;
4705  protected $redirect;
4706  protected $redirectRoute;
4707  protected $redirectAction;
4708  protected $errorBag = 'default';
4709  protected $dontFlash = array('password', 'password_confirmation');
4710  protected function getValidatorInstance()
4711  {
4712  $factory = $this->container->make('Illuminate\\Validation\\Factory');
4713  if (method_exists($this, 'validator')) {
4714  return $this->container->call(array($this, 'validator'), compact('factory'));
4715  }
4716  return $factory->make($this->all(), $this->container->call(array($this, 'rules')), $this->messages(), $this->attributes());
4717  }
4718  protected function failedValidation(Validator $validator)
4719  {
4720  throw new HttpResponseException($this->response($this->formatErrors($validator)));
4721  }
4722  protected function passesAuthorization()
4723  {
4724  if (method_exists($this, 'authorize')) {
4725  return $this->container->call(array($this, 'authorize'));
4726  }
4727  return false;
4728  }
4729  protected function failedAuthorization()
4730  {
4731  throw new HttpResponseException($this->forbiddenResponse());
4732  }
4733  public function response(array $errors)
4734  {
4735  if ($this->ajax() || $this->wantsJson()) {
4736  return new JsonResponse($errors, 422);
4737  }
4738  return $this->redirector->to($this->getRedirectUrl())->withInput($this->except($this->dontFlash))->withErrors($errors, $this->errorBag);
4739  }
4740  public function forbiddenResponse()
4741  {
4742  return new Response('Forbidden', 403);
4743  }
4744  protected function formatErrors(Validator $validator)
4745  {
4746  return $validator->errors()->getMessages();
4747  }
4748  protected function getRedirectUrl()
4749  {
4750  $url = $this->redirector->getUrlGenerator();
4751  if ($this->redirect) {
4752  return $url->to($this->redirect);
4753  } elseif ($this->redirectRoute) {
4754  return $url->route($this->redirectRoute);
4755  } elseif ($this->redirectAction) {
4756  return $url->action($this->redirectAction);
4757  }
4758  return $url->previous();
4759  }
4760  public function setRedirector(Redirector $redirector)
4761  {
4762  $this->redirector = $redirector;
4763  return $this;
4764  }
4766  {
4767  $this->container = $container;
4768  return $this;
4769  }
4770  public function messages()
4771  {
4772  return array();
4773  }
4774  public function attributes()
4775  {
4776  return array();
4777  }
4778 }
4780 
4781 use ArrayAccess;
4782 trait DispatchesCommands
4784  protected function dispatch($command)
4785  {
4786  return app('Illuminate\\Contracts\\Bus\\Dispatcher')->dispatch($command);
4787  }
4788  protected function dispatchFromArray($command, array $array)
4789  {
4790  return app('Illuminate\\Contracts\\Bus\\Dispatcher')->dispatchFromArray($command, $array);
4791  }
4792  protected function dispatchFrom($command, ArrayAccess $source, $extras = array())
4793  {
4794  return app('Illuminate\\Contracts\\Bus\\Dispatcher')->dispatchFrom($command, $source, $extras);
4795  }
4796 }
4798 
4801 {
4802  protected $providers = array('Illuminate\\Foundation\\Providers\\FormRequestServiceProvider');
4803 }
4805 
4810 {
4811  public function register()
4812  {
4813  }
4814  public function boot()
4815  {
4816  $this->app['events']->listen('router.matched', function () {
4817  $this->app->resolving(function (FormRequest $request, $app) {
4818  $this->initializeRequest($request, $app['request']);
4819  $request->setContainer($app)->setRedirector($app['Illuminate\\Routing\\Redirector']);
4820  });
4821  });
4822  }
4823  protected function initializeRequest(FormRequest $form, Request $current)
4824  {
4825  $files = $current->files->all();
4826  $files = is_array($files) ? array_filter($files) : $files;
4827  $form->initialize($current->query->all(), $current->request->all(), $current->attributes->all(), $current->cookies->all(), $files, $current->server->all(), $current->getContent());
4828  if ($session = $current->getSession()) {
4829  $form->setSession($session);
4830  }
4831  $form->setUserResolver($current->getUserResolver());
4832  $form->setRouteResolver($current->getRouteResolver());
4833  }
4834 }
4835 namespace Illuminate\Auth;
4836 
4839 {
4840  public function register()
4841  {
4842  $this->registerAuthenticator();
4843  $this->registerUserResolver();
4844  $this->registerRequestRebindHandler();
4845  }
4846  protected function registerAuthenticator()
4847  {
4848  $this->app->singleton('auth', function ($app) {
4849  $app['auth.loaded'] = true;
4850  return new AuthManager($app);
4851  });
4852  $this->app->singleton('auth.driver', function ($app) {
4853  return $app['auth']->driver();
4854  });
4855  }
4856  protected function registerUserResolver()
4857  {
4858  $this->app->bind('Illuminate\\Contracts\\Auth\\Authenticatable', function ($app) {
4859  return $app['auth']->user();
4860  });
4861  }
4862  protected function registerRequestRebindHandler()
4863  {
4864  $this->app->rebinding('request', function ($app, $request) {
4865  $request->setUserResolver(function () use($app) {
4866  return $app['auth']->user();
4867  });
4868  });
4869  }
4870 }
4872 
4875 {
4876  public function register()
4877  {
4878  Paginator::currentPathResolver(function () {
4879  return $this->app['request']->url();
4880  });
4881  Paginator::currentPageResolver(function () {
4882  return $this->app['request']->input('page');
4883  });
4884  }
4885 }
4887 
4891 {
4892  protected $namespace;
4893  public function boot(Router $router)
4894  {
4895  $this->setRootControllerNamespace();
4896  if ($this->app->routesAreCached()) {
4897  $this->loadCachedRoutes();
4898  } else {
4899  $this->loadRoutes();
4900  }
4901  }
4902  protected function setRootControllerNamespace()
4903  {
4904  if (is_null($this->namespace)) {
4905  return;
4906  }
4907  $this->app['Illuminate\\Contracts\\Routing\\UrlGenerator']->setRootControllerNamespace($this->namespace);
4908  }
4909  protected function loadCachedRoutes()
4910  {
4911  $this->app->booted(function () {
4912  require $this->app->getCachedRoutesPath();
4913  });
4914  }
4915  protected function loadRoutes()
4916  {
4917  $this->app->call(array($this, 'map'));
4918  }
4919  protected function loadRoutesFrom($path)
4920  {
4921  $router = $this->app['Illuminate\\Routing\\Router'];
4922  if (is_null($this->namespace)) {
4923  return require $path;
4924  }
4925  $router->group(array('namespace' => $this->namespace), function ($router) use($path) {
4926  require $path;
4927  });
4928  }
4929  public function register()
4930  {
4931  }
4932  public function __call($method, $parameters)
4933  {
4934  return call_user_func_array(array($this->app['router'], $method), $parameters);
4935  }
4936 }
4938 
4942 {
4943  protected $listen = array();
4944  protected $subscribe = array();
4945  public function boot(DispatcherContract $events)
4946  {
4947  foreach ($this->listen as $event => $listeners) {
4948  foreach ($listeners as $listener) {
4949  $events->listen($event, $listener);
4950  }
4951  }
4952  foreach ($this->subscribe as $subscriber) {
4953  $events->subscribe($subscriber);
4954  }
4955  }
4956  public function register()
4957  {
4958  }
4959  public function listens()
4960  {
4961  return $this->listen;
4962  }
4963 }
4965 
4968 {
4969  protected $defer = true;
4970  public function register()
4971  {
4972  $this->app->singleton('hash', function () {
4973  return new BcryptHasher();
4974  });
4975  }
4976  public function provides()
4977  {
4978  return array('hash');
4979  }
4980 }
4981 namespace Illuminate\Hashing;
4982 
4983 use RuntimeException;
4984 use Illuminate\Contracts\Hashing\Hasher as HasherContract;
4985 class BcryptHasher implements HasherContract
4986 {
4987  protected $rounds = 10;
4988  public function make($value, array $options = array())
4989  {
4990  $cost = isset($options['rounds']) ? $options['rounds'] : $this->rounds;
4991  $hash = password_hash($value, PASSWORD_BCRYPT, array('cost' => $cost));
4992  if ($hash === false) {
4993  throw new RuntimeException('Bcrypt hashing not supported.');
4994  }
4995  return $hash;
4996  }
4997  public function check($value, $hashedValue, array $options = array())
4998  {
4999  return password_verify($value, $hashedValue);
5000  }
5001  public function needsRehash($hashedValue, array $options = array())
5002  {
5003  $cost = isset($options['rounds']) ? $options['rounds'] : $this->rounds;
5004  return password_needs_rehash($hashedValue, PASSWORD_BCRYPT, array('cost' => $cost));
5005  }
5006  public function setRounds($rounds)
5007  {
5008  $this->rounds = (int) $rounds;
5009  return $this;
5010  }
5011 }
5013 
5014 interface Paginator
5015 {
5016  public function url($page);
5017  public function appends($key, $value = null);
5018  public function fragment($fragment = null);
5019  public function nextPageUrl();
5020  public function previousPageUrl();
5021  public function items();
5022  public function firstItem();
5023  public function lastItem();
5024  public function perPage();
5025  public function currentPage();
5026  public function hasPages();
5027  public function hasMorePages();
5028  public function isEmpty();
5029  public function render(Presenter $presenter = null);
5030 }
5031 namespace Illuminate\Pagination;
5032 
5033 use Closure;
5034 use ArrayIterator;
5035 abstract class AbstractPaginator
5036 {
5037  protected $items;
5038  protected $perPage;
5039  protected $currentPage;
5040  protected $path = '/';
5041  protected $query = array();
5042  protected $fragment = null;
5043  protected $pageName = 'page';
5044  protected static $currentPathResolver;
5045  protected static $currentPageResolver;
5046  protected static $presenterResolver;
5047  protected function isValidPageNumber($page)
5048  {
5049  return $page >= 1 && filter_var($page, FILTER_VALIDATE_INT) !== false;
5050  }
5051  public function getUrlRange($start, $end)
5052  {
5053  $urls = array();
5054  for ($page = $start; $page <= $end; $page++) {
5055  $urls[$page] = $this->url($page);
5056  }
5057  return $urls;
5058  }
5059  public function url($page)
5060  {
5061  if ($page <= 0) {
5062  $page = 1;
5063  }
5064  $parameters = array($this->pageName => $page);
5065  if (count($this->query) > 0) {
5066  $parameters = array_merge($this->query, $parameters);
5067  }
5068  return $this->path . '?' . http_build_query($parameters, null, '&') . $this->buildFragment();
5069  }
5070  public function previousPageUrl()
5071  {
5072  if ($this->currentPage() > 1) {
5073  return $this->url($this->currentPage() - 1);
5074  }
5075  }
5076  public function fragment($fragment = null)
5077  {
5078  if (is_null($fragment)) {
5079  return $this->fragment;
5080  }
5081  $this->fragment = $fragment;
5082  return $this;
5083  }
5084  public function appends($key, $value = null)
5085  {
5086  if (is_array($key)) {
5087  return $this->appendArray($key);
5088  }
5089  return $this->addQuery($key, $value);
5090  }
5091  protected function appendArray(array $keys)
5092  {
5093  foreach ($keys as $key => $value) {
5094  $this->addQuery($key, $value);
5095  }
5096  return $this;
5097  }
5098  public function addQuery($key, $value)
5099  {
5100  if ($key !== $this->pageName) {
5101  $this->query[$key] = $value;
5102  }
5103  return $this;
5104  }
5105  protected function buildFragment()
5106  {
5107  return $this->fragment ? '#' . $this->fragment : '';
5108  }
5109  public function items()
5110  {
5111  return $this->items->all();
5112  }
5113  public function firstItem()
5114  {
5115  return ($this->currentPage - 1) * $this->perPage + 1;
5116  }
5117  public function lastItem()
5118  {
5119  return $this->firstItem() + $this->count() - 1;
5120  }
5121  public function perPage()
5122  {
5123  return $this->perPage;
5124  }
5125  public function currentPage()
5126  {
5127  return $this->currentPage;
5128  }
5129  public function hasPages()
5130  {
5131  return !($this->currentPage() == 1 && !$this->hasMorePages());
5132  }
5133  public static function resolveCurrentPath($default = '/')
5134  {
5135  if (isset(static::$currentPathResolver)) {
5136  return call_user_func(static::$currentPathResolver);
5137  }
5138  return $default;
5139  }
5140  public static function currentPathResolver(Closure $resolver)
5141  {
5142  static::$currentPathResolver = $resolver;
5143  }
5144  public static function resolveCurrentPage($default = 1)
5145  {
5146  if (isset(static::$currentPageResolver)) {
5147  return call_user_func(static::$currentPageResolver);
5148  }
5149  return $default;
5150  }
5151  public static function currentPageResolver(Closure $resolver)
5152  {
5153  static::$currentPageResolver = $resolver;
5154  }
5155  public static function presenter(Closure $resolver)
5156  {
5157  static::$presenterResolver = $resolver;
5158  }
5159  public function setPageName($name)
5160  {
5161  $this->pageName = $name;
5162  return $this;
5163  }
5164  public function setPath($path)
5165  {
5166  $this->path = $path;
5167  return $this;
5168  }
5169  public function getIterator()
5170  {
5171  return new ArrayIterator($this->items->all());
5172  }
5173  public function isEmpty()
5174  {
5175  return $this->items->isEmpty();
5176  }
5177  public function count()
5178  {
5179  return $this->items->count();
5180  }
5181  public function getCollection()
5182  {
5183  return $this->items;
5184  }
5185  public function offsetExists($key)
5186  {
5187  return $this->items->has($key);
5188  }
5189  public function offsetGet($key)
5190  {
5191  return $this->items->get($key);
5192  }
5193  public function offsetSet($key, $value)
5194  {
5195  $this->items->put($key, $value);
5196  }
5197  public function offsetUnset($key)
5198  {
5199  $this->items->forget($key);
5200  }
5201  public function __call($method, $parameters)
5202  {
5203  return call_user_func_array(array($this->getCollection(), $method), $parameters);
5204  }
5205  public function __toString()
5206  {
5207  return $this->render();
5208  }
5209 }
5210 namespace Illuminate\Pagination;
5211 
5212 use Countable;
5213 use ArrayAccess;
5214 use IteratorAggregate;
5219 use Illuminate\Contracts\Pagination\Paginator as PaginatorContract;
5220 class Paginator extends AbstractPaginator implements Arrayable, ArrayAccess, Countable, IteratorAggregate, Jsonable, PaginatorContract
5221 {
5222  protected $hasMore;
5223  public function __construct($items, $perPage, $currentPage = null, array $options = array())
5224  {
5225  foreach ($options as $key => $value) {
5226  $this->{$key} = $value;
5227  }
5228  $this->perPage = $perPage;
5229  $this->currentPage = $this->setCurrentPage($currentPage);
5230  $this->path = $this->path != '/' ? rtrim($this->path, '/') . '/' : $this->path;
5231  $this->items = $items instanceof Collection ? $items : Collection::make($items);
5232  $this->checkForMorePages();
5233  }
5234  protected function setCurrentPage($currentPage)
5235  {
5236  $currentPage = $currentPage ?: static::resolveCurrentPage();
5237  return $this->isValidPageNumber($currentPage) ? (int) $currentPage : 1;
5238  }
5239  protected function checkForMorePages()
5240  {
5241  $this->hasMore = count($this->items) > $this->perPage;
5242  $this->items = $this->items->slice(0, $this->perPage);
5243  }
5244  public function nextPageUrl()
5245  {
5246  if ($this->hasMore) {
5247  return $this->url($this->currentPage() + 1);
5248  }
5249  }
5250  public function hasMorePages()
5251  {
5252  return $this->hasMore;
5253  }
5254  public function render(Presenter $presenter = null)
5255  {
5256  if (is_null($presenter) && static::$presenterResolver) {
5257  $presenter = call_user_func(static::$presenterResolver, $this);
5258  }
5259  $presenter = $presenter ?: new SimpleBootstrapThreePresenter($this);
5260  return $presenter->render();
5261  }
5262  public function toArray()
5263  {
5264  return array('per_page' => $this->perPage(), 'current_page' => $this->currentPage(), 'next_page_url' => $this->nextPageUrl(), 'prev_page_url' => $this->previousPageUrl(), 'from' => $this->firstItem(), 'to' => $this->lastItem(), 'data' => $this->items->toArray());
5265  }
5266  public function toJson($options = 0)
5267  {
5268  return json_encode($this->toArray(), $options);
5269  }
5270 }
5272 
5273 use Mockery;
5274 use RuntimeException;
5276 abstract class Facade
5277 {
5278  protected static $app;
5279  protected static $resolvedInstance;
5280  public static function swap($instance)
5281  {
5282  static::$resolvedInstance[static::getFacadeAccessor()] = $instance;
5283  static::$app->instance(static::getFacadeAccessor(), $instance);
5284  }
5285  public static function shouldReceive()
5286  {
5287  $name = static::getFacadeAccessor();
5288  if (static::isMock()) {
5289  $mock = static::$resolvedInstance[$name];
5290  } else {
5291  $mock = static::createFreshMockInstance($name);
5292  }
5293  return call_user_func_array(array($mock, 'shouldReceive'), func_get_args());
5294  }
5295  protected static function createFreshMockInstance($name)
5296  {
5297  static::$resolvedInstance[$name] = $mock = static::createMockByName($name);
5298  if (isset(static::$app)) {
5299  static::$app->instance($name, $mock);
5300  }
5301  return $mock;
5302  }
5303  protected static function createMockByName($name)
5304  {
5305  $class = static::getMockableClass($name);
5306  return $class ? Mockery::mock($class) : Mockery::mock();
5307  }
5308  protected static function isMock()
5309  {
5310  $name = static::getFacadeAccessor();
5311  return isset(static::$resolvedInstance[$name]) && static::$resolvedInstance[$name] instanceof MockInterface;
5312  }
5313  protected static function getMockableClass()
5314  {
5315  if ($root = static::getFacadeRoot()) {
5316  return get_class($root);
5317  }
5318  }
5319  public static function getFacadeRoot()
5320  {
5321  return static::resolveFacadeInstance(static::getFacadeAccessor());
5322  }
5323  protected static function getFacadeAccessor()
5324  {
5325  throw new RuntimeException('Facade does not implement getFacadeAccessor method.');
5326  }
5327  protected static function resolveFacadeInstance($name)
5328  {
5329  if (is_object($name)) {
5330  return $name;
5331  }
5332  if (isset(static::$resolvedInstance[$name])) {
5333  return static::$resolvedInstance[$name];
5334  }
5335  return static::$resolvedInstance[$name] = static::$app[$name];
5336  }
5337  public static function clearResolvedInstance($name)
5338  {
5339  unset(static::$resolvedInstance[$name]);
5340  }
5341  public static function clearResolvedInstances()
5342  {
5343  static::$resolvedInstance = array();
5344  }
5345  public static function getFacadeApplication()
5346  {
5347  return static::$app;
5348  }
5349  public static function setFacadeApplication($app)
5350  {
5351  static::$app = $app;
5352  }
5353  public static function __callStatic($method, $args)
5354  {
5355  $instance = static::getFacadeRoot();
5356  switch (count($args)) {
5357  case 0:
5358  return $instance->{$method}();
5359  case 1:
5360  return $instance->{$method}($args[0]);
5361  case 2:
5362  return $instance->{$method}($args[0], $args[1]);
5363  case 3:
5364  return $instance->{$method}($args[0], $args[1], $args[2]);
5365  case 4:
5366  return $instance->{$method}($args[0], $args[1], $args[2], $args[3]);
5367  default:
5368  return call_user_func_array(array($instance, $method), $args);
5369  }
5370  }
5371 }
5373 
5374 use Closure;
5375 use BadMethodCallException;
5376 trait Macroable
5378  protected static $macros = array();
5379  public static function macro($name, callable $macro)
5380  {
5381  static::$macros[$name] = $macro;
5382  }
5383  public static function hasMacro($name)
5384  {
5385  return isset(static::$macros[$name]);
5386  }
5387  public static function __callStatic($method, $parameters)
5388  {
5389  if (static::hasMacro($method)) {
5390  if (static::$macros[$method] instanceof Closure) {
5391  return call_user_func_array(Closure::bind(static::$macros[$method], null, get_called_class()), $parameters);
5392  } else {
5393  return call_user_func_array(static::$macros[$method], $parameters);
5394  }
5395  }
5396  throw new BadMethodCallException("Method {$method} does not exist.");
5397  }
5398  public function __call($method, $parameters)
5399  {
5400  if (static::hasMacro($method)) {
5401  if (static::$macros[$method] instanceof Closure) {
5402  return call_user_func_array(static::$macros[$method]->bindTo($this, get_class($this)), $parameters);
5403  } else {
5404  return call_user_func_array(static::$macros[$method], $parameters);
5405  }
5406  }
5407  throw new BadMethodCallException("Method {$method} does not exist.");
5408  }
5409 }
5410 namespace Illuminate\Support;
5411 
5413 class Arr
5414 {
5415  use Macroable;
5416  public static function add($array, $key, $value)
5417  {
5418  if (is_null(static::get($array, $key))) {
5419  static::set($array, $key, $value);
5420  }
5421  return $array;
5422  }
5423  public static function build($array, callable $callback)
5424  {
5425  $results = array();
5426  foreach ($array as $key => $value) {
5427  list($innerKey, $innerValue) = call_user_func($callback, $key, $value);
5428  $results[$innerKey] = $innerValue;
5429  }
5430  return $results;
5431  }
5432  public static function divide($array)
5433  {
5434  return array(array_keys($array), array_values($array));
5435  }
5436  public static function dot($array, $prepend = '')
5437  {
5438  $results = array();
5439  foreach ($array as $key => $value) {
5440  if (is_array($value)) {
5441  $results = array_merge($results, static::dot($value, $prepend . $key . '.'));
5442  } else {
5443  $results[$prepend . $key] = $value;
5444  }
5445  }
5446  return $results;
5447  }
5448  public static function except($array, $keys)
5449  {
5450  foreach ((array) $keys as $key) {
5451  static::forget($array, $key);
5452  }
5453  return $array;
5454  }
5455  public static function fetch($array, $key)
5456  {
5457  foreach (explode('.', $key) as $segment) {
5458  $results = array();
5459  foreach ($array as $value) {
5460  if (array_key_exists($segment, $value = (array) $value)) {
5461  $results[] = $value[$segment];
5462  }
5463  }
5464  $array = array_values($results);
5465  }
5466  return array_values($results);
5467  }
5468  public static function first($array, callable $callback, $default = null)
5469  {
5470  foreach ($array as $key => $value) {
5471  if (call_user_func($callback, $key, $value)) {
5472  return $value;
5473  }
5474  }
5475  return value($default);
5476  }
5477  public static function last($array, callable $callback, $default = null)
5478  {
5479  return static::first(array_reverse($array), $callback, $default);
5480  }
5481  public static function flatten($array)
5482  {
5483  $return = array();
5484  array_walk_recursive($array, function ($x) use(&$return) {
5485  $return[] = $x;
5486  });
5487  return $return;
5488  }
5489  public static function forget(&$array, $keys)
5490  {
5491  $original =& $array;
5492  foreach ((array) $keys as $key) {
5493  $parts = explode('.', $key);
5494  while (count($parts) > 1) {
5495  $part = array_shift($parts);
5496  if (isset($array[$part]) && is_array($array[$part])) {
5497  $array =& $array[$part];
5498  }
5499  }
5500  unset($array[array_shift($parts)]);
5501  $array =& $original;
5502  }
5503  }
5504  public static function get($array, $key, $default = null)
5505  {
5506  if (is_null($key)) {
5507  return $array;
5508  }
5509  if (isset($array[$key])) {
5510  return $array[$key];
5511  }
5512  foreach (explode('.', $key) as $segment) {
5513  if (!is_array($array) || !array_key_exists($segment, $array)) {
5514  return value($default);
5515  }
5516  $array = $array[$segment];
5517  }
5518  return $array;
5519  }
5520  public static function has($array, $key)
5521  {
5522  if (empty($array) || is_null($key)) {
5523  return false;
5524  }
5525  if (array_key_exists($key, $array)) {
5526  return true;
5527  }
5528  foreach (explode('.', $key) as $segment) {
5529  if (!is_array($array) || !array_key_exists($segment, $array)) {
5530  return false;
5531  }
5532  $array = $array[$segment];
5533  }
5534  return true;
5535  }
5536  public static function only($array, $keys)
5537  {
5538  return array_intersect_key($array, array_flip((array) $keys));
5539  }
5540  public static function pluck($array, $value, $key = null)
5541  {
5542  $results = array();
5543  foreach ($array as $item) {
5544  $itemValue = data_get($item, $value);
5545  if (is_null($key)) {
5546  $results[] = $itemValue;
5547  } else {
5548  $itemKey = data_get($item, $key);
5549  $results[$itemKey] = $itemValue;
5550  }
5551  }
5552  return $results;
5553  }
5554  public static function pull(&$array, $key, $default = null)
5555  {
5556  $value = static::get($array, $key, $default);
5557  static::forget($array, $key);
5558  return $value;
5559  }
5560  public static function set(&$array, $key, $value)
5561  {
5562  if (is_null($key)) {
5563  return $array = $value;
5564  }
5565  $keys = explode('.', $key);
5566  while (count($keys) > 1) {
5567  $key = array_shift($keys);
5568  if (!isset($array[$key]) || !is_array($array[$key])) {
5569  $array[$key] = array();
5570  }
5571  $array =& $array[$key];
5572  }
5573  $array[array_shift($keys)] = $value;
5574  return $array;
5575  }
5576  public static function sort($array, callable $callback)
5577  {
5578  return Collection::make($array)->sortBy($callback)->all();
5579  }
5580  public static function where($array, callable $callback)
5581  {
5582  $filtered = array();
5583  foreach ($array as $key => $value) {
5584  if (call_user_func($callback, $key, $value)) {
5585  $filtered[$key] = $value;
5586  }
5587  }
5588  return $filtered;
5589  }
5590 }
5591 namespace Illuminate\Support;
5592 
5593 use RuntimeException;
5596 class Str
5597 {
5598  use Macroable;
5599  protected static $snakeCache = array();
5600  protected static $camelCache = array();
5601  protected static $studlyCache = array();
5602  public static function ascii($value)
5603  {
5604  return StaticStringy::toAscii($value);
5605  }
5606  public static function camel($value)
5607  {
5608  if (isset(static::$camelCache[$value])) {
5609  return static::$camelCache[$value];
5610  }
5611  return static::$camelCache[$value] = lcfirst(static::studly($value));
5612  }
5613  public static function contains($haystack, $needles)
5614  {
5615  foreach ((array) $needles as $needle) {
5616  if ($needle != '' && strpos($haystack, $needle) !== false) {
5617  return true;
5618  }
5619  }
5620  return false;
5621  }
5622  public static function endsWith($haystack, $needles)
5623  {
5624  foreach ((array) $needles as $needle) {
5625  if ((string) $needle === substr($haystack, -strlen($needle))) {
5626  return true;
5627  }
5628  }
5629  return false;
5630  }
5631  public static function finish($value, $cap)
5632  {
5633  $quoted = preg_quote($cap, '/');
5634  return preg_replace('/(?:' . $quoted . ')+$/', '', $value) . $cap;
5635  }
5636  public static function is($pattern, $value)
5637  {
5638  if ($pattern == $value) {
5639  return true;
5640  }
5641  $pattern = preg_quote($pattern, '#');
5642  $pattern = str_replace('\\*', '.*', $pattern) . '\\z';
5643  return (bool) preg_match('#^' . $pattern . '#', $value);
5644  }
5645  public static function length($value)
5646  {
5647  return mb_strlen($value);
5648  }
5649  public static function limit($value, $limit = 100, $end = '...')
5650  {
5651  if (mb_strlen($value) <= $limit) {
5652  return $value;
5653  }
5654  return rtrim(mb_substr($value, 0, $limit, 'UTF-8')) . $end;
5655  }
5656  public static function lower($value)
5657  {
5658  return mb_strtolower($value);
5659  }
5660  public static function words($value, $words = 100, $end = '...')
5661  {
5662  preg_match('/^\\s*+(?:\\S++\\s*+){1,' . $words . '}/u', $value, $matches);
5663  if (!isset($matches[0]) || strlen($value) === strlen($matches[0])) {
5664  return $value;
5665  }
5666  return rtrim($matches[0]) . $end;
5667  }
5668  public static function parseCallback($callback, $default)
5669  {
5670  return static::contains($callback, '@') ? explode('@', $callback, 2) : array($callback, $default);
5671  }
5672  public static function plural($value, $count = 2)
5673  {
5674  return Pluralizer::plural($value, $count);
5675  }
5676  public static function random($length = 16)
5677  {
5678  if (!function_exists('openssl_random_pseudo_bytes')) {
5679  throw new RuntimeException('OpenSSL extension is required.');
5680  }
5681  $bytes = openssl_random_pseudo_bytes($length * 2);
5682  if ($bytes === false) {
5683  throw new RuntimeException('Unable to generate random string.');
5684  }
5685  return substr(str_replace(array('/', '+', '='), '', base64_encode($bytes)), 0, $length);
5686  }
5687  public static function quickRandom($length = 16)
5688  {
5689  $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
5690  return substr(str_shuffle(str_repeat($pool, $length)), 0, $length);
5691  }
5692  public static function upper($value)
5693  {
5694  return mb_strtoupper($value);
5695  }
5696  public static function title($value)
5697  {
5698  return mb_convert_case($value, MB_CASE_TITLE, 'UTF-8');
5699  }
5700  public static function singular($value)
5701  {
5702  return Pluralizer::singular($value);
5703  }
5704  public static function slug($title, $separator = '-')
5705  {
5706  $title = static::ascii($title);
5707  $flip = $separator == '-' ? '_' : '-';
5708  $title = preg_replace('![' . preg_quote($flip) . ']+!u', $separator, $title);
5709  $title = preg_replace('![^' . preg_quote($separator) . '\\pL\\pN\\s]+!u', '', mb_strtolower($title));
5710  $title = preg_replace('![' . preg_quote($separator) . '\\s]+!u', $separator, $title);
5711  return trim($title, $separator);
5712  }
5713  public static function snake($value, $delimiter = '_')
5714  {
5715  $key = $value . $delimiter;
5716  if (isset(static::$snakeCache[$key])) {
5717  return static::$snakeCache[$key];
5718  }
5719  if (!ctype_lower($value)) {
5720  $value = strtolower(preg_replace('/(.)(?=[A-Z])/', '$1' . $delimiter, $value));
5721  }
5722  return static::$snakeCache[$key] = $value;
5723  }
5724  public static function startsWith($haystack, $needles)
5725  {
5726  foreach ((array) $needles as $needle) {
5727  if ($needle != '' && strpos($haystack, $needle) === 0) {
5728  return true;
5729  }
5730  }
5731  return false;
5732  }
5733  public static function studly($value)
5734  {
5735  $key = $value;
5736  if (isset(static::$studlyCache[$key])) {
5737  return static::$studlyCache[$key];
5738  }
5739  $value = ucwords(str_replace(array('-', '_'), ' ', $value));
5740  return static::$studlyCache[$key] = str_replace(' ', '', $value);
5741  }
5742 }
5743 namespace Symfony\Component\Debug;
5744 
5745 use Psr\Log\LogLevel;
5755 {
5756  const TYPE_DEPRECATION = -100;
5757  private $levels = array(E_DEPRECATED => 'Deprecated', E_USER_DEPRECATED => 'User Deprecated', E_NOTICE => 'Notice', E_USER_NOTICE => 'User Notice', E_STRICT => 'Runtime Notice', E_WARNING => 'Warning', E_USER_WARNING => 'User Warning', E_COMPILE_WARNING => 'Compile Warning', E_CORE_WARNING => 'Core Warning', E_USER_ERROR => 'User Error', E_RECOVERABLE_ERROR => 'Catchable Fatal Error', E_COMPILE_ERROR => 'Compile Error', E_PARSE => 'Parse Error', E_ERROR => 'Error', E_CORE_ERROR => 'Core Error');
5758  private $loggers = array(E_DEPRECATED => array(null, LogLevel::INFO), E_USER_DEPRECATED => array(null, LogLevel::INFO), E_NOTICE => array(null, LogLevel::NOTICE), E_USER_NOTICE => array(null, LogLevel::NOTICE), E_STRICT => array(null, LogLevel::NOTICE), E_WARNING => array(null, LogLevel::WARNING), E_USER_WARNING => array(null, LogLevel::WARNING), E_COMPILE_WARNING => array(null, LogLevel::WARNING), E_CORE_WARNING => array(null, LogLevel::WARNING), E_USER_ERROR => array(null, LogLevel::ERROR), E_RECOVERABLE_ERROR => array(null, LogLevel::ERROR), E_COMPILE_ERROR => array(null, LogLevel::EMERGENCY), E_PARSE => array(null, LogLevel::EMERGENCY), E_ERROR => array(null, LogLevel::EMERGENCY), E_CORE_ERROR => array(null, LogLevel::EMERGENCY));
5759  private $thrownErrors = 8191;
5760  private $scopedErrors = 8191;
5761  private $tracedErrors = 30715;
5762  private $screamedErrors = 85;
5763  private $loggedErrors = 0;
5764  private $loggedTraces = array();
5765  private $isRecursive = 0;
5766  private $exceptionHandler;
5767  private static $reservedMemory;
5768  private static $stackedErrors = array();
5769  private static $stackedErrorLevels = array();
5770  private $displayErrors = 8191;
5771  public static function register($handler = null, $replace = true)
5772  {
5773  if (null === self::$reservedMemory) {
5774  self::$reservedMemory = str_repeat('x', 10240);
5775  register_shutdown_function(__CLASS__ . '::handleFatalError');
5776  }
5777  $levels = -1;
5778  if ($handlerIsNew = !$handler instanceof self) {
5779  if (null !== $handler) {
5780  $levels = $replace ? $handler : 0;
5781  $replace = true;
5782  }
5783  $handler = new static();
5784  }
5785  $prev = set_error_handler(array($handler, 'handleError'), $handler->thrownErrors | $handler->loggedErrors);
5786  if ($handlerIsNew && is_array($prev) && $prev[0] instanceof self) {
5787  $handler = $prev[0];
5788  $replace = false;
5789  }
5790  if ($replace || !$prev) {
5791  $handler->setExceptionHandler(set_exception_handler(array($handler, 'handleException')));
5792  } else {
5793  restore_error_handler();
5794  }
5795  $handler->throwAt($levels & $handler->thrownErrors, true);
5796  return $handler;
5797  }
5798  public function setDefaultLogger(LoggerInterface $logger, $levels = null, $replace = false)
5799  {
5800  $loggers = array();
5801  if (is_array($levels)) {
5802  foreach ($levels as $type => $logLevel) {
5803  if (empty($this->loggers[$type][0]) || $replace) {
5804  $loggers[$type] = array($logger, $logLevel);
5805  }
5806  }
5807  } else {
5808  if (null === $levels) {
5809  $levels = E_ALL | E_STRICT;
5810  }
5811  foreach ($this->loggers as $type => $log) {
5812  if ($type & $levels && (empty($log[0]) || $replace)) {
5813  $log[0] = $logger;
5814  $loggers[$type] = $log;
5815  }
5816  }
5817  }
5818  $this->setLoggers($loggers);
5819  }
5820  public function setLoggers(array $loggers)
5821  {
5822  $prevLogged = $this->loggedErrors;
5823  $prev = $this->loggers;
5824  foreach ($loggers as $type => $log) {
5825  if (!isset($prev[$type])) {
5826  throw new \InvalidArgumentException('Unknown error type: ' . $type);
5827  }
5828  if (!is_array($log)) {
5829  $log = array($log);
5830  } elseif (!array_key_exists(0, $log)) {
5831  throw new \InvalidArgumentException('No logger provided');
5832  }
5833  if (null === $log[0]) {
5834  $this->loggedErrors &= ~$type;
5835  } elseif ($log[0] instanceof LoggerInterface) {
5836  $this->loggedErrors |= $type;
5837  } else {
5838  throw new \InvalidArgumentException('Invalid logger provided');
5839  }
5840  $this->loggers[$type] = $log + $prev[$type];
5841  }
5842  $this->reRegister($prevLogged | $this->thrownErrors);
5843  return $prev;
5844  }
5845  public function setExceptionHandler($handler)
5846  {
5847  if (null !== $handler && !is_callable($handler)) {
5848  throw new \LogicException('The exception handler must be a valid PHP callable.');
5849  }
5850  $prev = $this->exceptionHandler;
5851  $this->exceptionHandler = $handler;
5852  return $prev;
5853  }
5854  public function throwAt($levels, $replace = false)
5855  {
5856  $prev = $this->thrownErrors;
5857  $this->thrownErrors = ($levels | E_RECOVERABLE_ERROR | E_USER_ERROR) & ~E_USER_DEPRECATED & ~E_DEPRECATED;
5858  if (!$replace) {
5859  $this->thrownErrors |= $prev;
5860  }
5861  $this->reRegister($prev | $this->loggedErrors);
5862  $this->displayErrors = $this->thrownErrors;
5863  return $prev;
5864  }
5865  public function scopeAt($levels, $replace = false)
5866  {
5867  $prev = $this->scopedErrors;
5868  $this->scopedErrors = (int) $levels;
5869  if (!$replace) {
5870  $this->scopedErrors |= $prev;
5871  }
5872  return $prev;
5873  }
5874  public function traceAt($levels, $replace = false)
5875  {
5876  $prev = $this->tracedErrors;
5877  $this->tracedErrors = (int) $levels;
5878  if (!$replace) {
5879  $this->tracedErrors |= $prev;
5880  }
5881  return $prev;
5882  }
5883  public function screamAt($levels, $replace = false)
5884  {
5885  $prev = $this->screamedErrors;
5886  $this->screamedErrors = (int) $levels;
5887  if (!$replace) {
5888  $this->screamedErrors |= $prev;
5889  }
5890  return $prev;
5891  }
5892  private function reRegister($prev)
5893  {
5894  if ($prev !== $this->thrownErrors | $this->loggedErrors) {
5895  $handler = set_error_handler('var_dump', 0);
5896  $handler = is_array($handler) ? $handler[0] : null;
5897  restore_error_handler();
5898  if ($handler === $this) {
5899  restore_error_handler();
5900  set_error_handler(array($this, 'handleError'), $this->thrownErrors | $this->loggedErrors);
5901  }
5902  }
5903  }
5904  public function handleError($type, $message, $file, $line, array $context)
5905  {
5906  $level = error_reporting() | E_RECOVERABLE_ERROR | E_USER_ERROR;
5907  $log = $this->loggedErrors & $type;
5908  $throw = $this->thrownErrors & $type & $level;
5909  $type &= $level | $this->screamedErrors;
5910  if ($type && ($log || $throw)) {
5911  if (PHP_VERSION_ID < 50400 && isset($context['GLOBALS']) && $this->scopedErrors & $type) {
5912  $e = $context;
5913  unset($e['GLOBALS'], $context);
5914  $context = $e;
5915  }
5916  if ($throw) {
5917  if ($this->scopedErrors & $type && class_exists('Symfony\\Component\\Debug\\Exception\\ContextErrorException')) {
5918  $throw = new ContextErrorException($this->levels[$type] . ': ' . $message, 0, $type, $file, $line, $context);
5919  } else {
5920  $throw = new \ErrorException($this->levels[$type] . ': ' . $message, 0, $type, $file, $line);
5921  }
5922  if (PHP_VERSION_ID <= 50407 && (PHP_VERSION_ID >= 50400 || PHP_VERSION_ID <= 50317)) {
5923  $throw->errorHandlerCanary = new ErrorHandlerCanary();
5924  }
5925  throw $throw;
5926  }
5927  $e = md5("{$type}/{$line}/{$file} {$message}", true);
5928  $trace = true;
5929  if (!($this->tracedErrors & $type) || isset($this->loggedTraces[$e])) {
5930  $trace = false;
5931  } else {
5932  $this->loggedTraces[$e] = 1;
5933  }
5934  $e = compact('type', 'file', 'line', 'level');
5935  if ($type & $level) {
5936  if ($this->scopedErrors & $type) {
5937  $e['context'] = $context;
5938  if ($trace) {
5939  $e['stack'] = debug_backtrace(true);
5940  }
5941  } elseif ($trace) {
5942  $e['stack'] = debug_backtrace(PHP_VERSION_ID >= 50306 ? DEBUG_BACKTRACE_IGNORE_ARGS : false);
5943  }
5944  }
5945  if ($this->isRecursive) {
5946  $log = 0;
5947  } elseif (self::$stackedErrorLevels) {
5948  self::$stackedErrors[] = array($this->loggers[$type], $message, $e);
5949  } else {
5950  try {
5951  $this->isRecursive = true;
5952  $this->loggers[$type][0]->log($this->loggers[$type][1], $message, $e);
5953  $this->isRecursive = false;
5954  } catch (\Exception $e) {
5955  $this->isRecursive = false;
5956  throw $e;
5957  }
5958  }
5959  }
5960  return $type && $log;
5961  }
5962  public function handleException(\Exception $exception, array $error = null)
5963  {
5964  $level = error_reporting();
5965  if ($this->loggedErrors & E_ERROR & ($level | $this->screamedErrors)) {
5966  $e = array('type' => E_ERROR, 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'level' => $level, 'stack' => $exception->getTrace());
5967  if ($exception instanceof FatalErrorException) {
5968  $message = 'Fatal ' . $exception->getMessage();
5969  } elseif ($exception instanceof \ErrorException) {
5970  $message = 'Uncaught ' . $exception->getMessage();
5971  if ($exception instanceof ContextErrorException) {
5972  $e['context'] = $exception->getContext();
5973  }
5974  } else {
5975  $message = 'Uncaught Exception: ' . $exception->getMessage();
5976  }
5977  if ($this->loggedErrors & $e['type']) {
5978  $this->loggers[$e['type']][0]->log($this->loggers[$e['type']][1], $message, $e);
5979  }
5980  }
5981  if ($exception instanceof FatalErrorException && !$exception instanceof OutOfMemoryException && $error) {
5982  foreach ($this->getFatalErrorHandlers() as $handler) {
5983  if ($e = $handler->handleError($error, $exception)) {
5984  $exception = $e;
5985  break;
5986  }
5987  }
5988  }
5989  if (empty($this->exceptionHandler)) {
5990  throw $exception;
5991  }
5992  try {
5993  call_user_func($this->exceptionHandler, $exception);
5994  } catch (\Exception $handlerException) {
5995  $this->exceptionHandler = null;
5996  $this->handleException($handlerException);
5997  }
5998  }
5999  public static function handleFatalError(array $error = null)
6000  {
6001  self::$reservedMemory = '';
6002  $handler = set_error_handler('var_dump', 0);
6003  $handler = is_array($handler) ? $handler[0] : null;
6004  restore_error_handler();
6005  if ($handler instanceof self) {
6006  if (null === $error) {
6007  $error = error_get_last();
6008  }
6009  try {
6010  while (self::$stackedErrorLevels) {
6011  static::unstackErrors();
6012  }
6013  } catch (\Exception $exception) {
6014  }
6015  if ($error && $error['type'] & (E_PARSE | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR)) {
6016  $handler->throwAt(0, true);
6017  if (0 === strpos($error['message'], 'Allowed memory') || 0 === strpos($error['message'], 'Out of memory')) {
6018  $exception = new OutOfMemoryException($handler->levels[$error['type']] . ': ' . $error['message'], 0, $error['type'], $error['file'], $error['line'], 2, false);
6019  } else {
6020  $exception = new FatalErrorException($handler->levels[$error['type']] . ': ' . $error['message'], 0, $error['type'], $error['file'], $error['line'], 2, true);
6021  }
6022  } elseif (!isset($exception)) {
6023  return;
6024  }
6025  try {
6026  $handler->handleException($exception, $error);
6027  } catch (FatalErrorException $e) {
6028  }
6029  }
6030  }
6031  public static function stackErrors()
6032  {
6033  self::$stackedErrorLevels[] = error_reporting(error_reporting() | E_PARSE | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR);
6034  }
6035  public static function unstackErrors()
6036  {
6037  $level = array_pop(self::$stackedErrorLevels);
6038  if (null !== $level) {
6039  $e = error_reporting($level);
6040  if ($e !== ($level | E_PARSE | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR)) {
6041  error_reporting($e);
6042  }
6043  }
6044  if (empty(self::$stackedErrorLevels)) {
6045  $errors = self::$stackedErrors;
6046  self::$stackedErrors = array();
6047  foreach ($errors as $e) {
6048  $e[0][0]->log($e[0][1], $e[1], $e[2]);
6049  }
6050  }
6051  }
6052  protected function getFatalErrorHandlers()
6053  {
6055  }
6056  public function setLevel($level)
6057  {
6058  $level = null === $level ? error_reporting() : $level;
6059  $this->throwAt($level, true);
6060  }
6061  public function setDisplayErrors($displayErrors)
6062  {
6063  if ($displayErrors) {
6064  $this->throwAt($this->displayErrors, true);
6065  } else {
6066  $displayErrors = $this->displayErrors;
6067  $this->throwAt(0, true);
6068  $this->displayErrors = $displayErrors;
6069  }
6070  }
6071  public static function setLogger(LoggerInterface $logger, $channel = 'deprecation')
6072  {
6073  $handler = set_error_handler('var_dump', 0);
6074  $handler = is_array($handler) ? $handler[0] : null;
6075  restore_error_handler();
6076  if (!$handler instanceof self) {
6077  return;
6078  }
6079  if ('deprecation' === $channel) {
6080  $handler->setDefaultLogger($logger, E_DEPRECATED | E_USER_DEPRECATED, true);
6081  $handler->screamAt(E_DEPRECATED | E_USER_DEPRECATED);
6082  } elseif ('scream' === $channel) {
6083  $handler->setDefaultLogger($logger, E_ALL | E_STRICT, false);
6084  $handler->screamAt(E_ALL | E_STRICT);
6085  } elseif ('emergency' === $channel) {
6086  $handler->setDefaultLogger($logger, E_PARSE | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR, true);
6087  $handler->screamAt(E_PARSE | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR);
6088  }
6089  }
6090  public function handle($level, $message, $file = 'unknown', $line = 0, $context = array())
6091  {
6092  return $this->handleError($level, $message, $file, $line, (array) $context);
6093  }
6094  public function handleFatal()
6095  {
6096  static::handleFatalError();
6097  }
6098 }
6100 {
6101  private static $displayErrors = null;
6102  public function __construct()
6103  {
6104  if (null === self::$displayErrors) {
6105  self::$displayErrors = ini_set('display_errors', 1);
6106  }
6107  }
6108  public function __destruct()
6109  {
6110  if (null !== self::$displayErrors) {
6111  ini_set('display_errors', self::$displayErrors);
6112  self::$displayErrors = null;
6113  }
6114  }
6115 }
6117 
6119 class ErrorHandler extends DebugErrorHandler
6120 {
6121 }
6123 
6124 use ArrayAccess;
6125 use Illuminate\Contracts\Config\Repository as ConfigContract;
6126 class Repository implements ArrayAccess, ConfigContract
6127 {
6128  protected $items = array();
6129  public function __construct(array $items = array())
6130  {
6131  $this->items = $items;
6132  }
6133  public function has($key)
6134  {
6135  return array_has($this->items, $key);
6136  }
6137  public function get($key, $default = null)
6138  {
6139  return array_get($this->items, $key, $default);
6140  }
6141  public function set($key, $value = null)
6142  {
6143  if (is_array($key)) {
6144  foreach ($key as $innerKey => $innerValue) {
6145  array_set($this->items, $innerKey, $innerValue);
6146  }
6147  } else {
6148  array_set($this->items, $key, $value);
6149  }
6150  }
6151  public function prepend($key, $value)
6152  {
6153  $array = $this->get($key);
6154  array_unshift($array, $value);
6155  $this->set($key, $array);
6156  }
6157  public function push($key, $value)
6158  {
6159  $array = $this->get($key);
6160  $array[] = $value;
6161  $this->set($key, $array);
6162  }
6163  public function all()
6164  {
6165  return $this->items;
6166  }
6167  public function offsetExists($key)
6168  {
6169  return $this->has($key);
6170  }
6171  public function offsetGet($key)
6172  {
6173  return $this->get($key);
6174  }
6175  public function offsetSet($key, $value)
6176  {
6177  $this->set($key, $value);
6178  }
6179  public function offsetUnset($key)
6180  {
6181  $this->set($key, null);
6182  }
6183 }
6184 namespace Illuminate\Support;
6185 
6187 {
6188  protected $parsed = array();
6189  public function parseKey($key)
6190  {
6191  if (isset($this->parsed[$key])) {
6192  return $this->parsed[$key];
6193  }
6194  if (strpos($key, '::') === false) {
6195  $segments = explode('.', $key);
6196  $parsed = $this->parseBasicSegments($segments);
6197  } else {
6198  $parsed = $this->parseNamespacedSegments($key);
6199  }
6200  return $this->parsed[$key] = $parsed;
6201  }
6202  protected function parseBasicSegments(array $segments)
6203  {
6204  $group = $segments[0];
6205  if (count($segments) == 1) {
6206  return array(null, $group, null);
6207  } else {
6208  $item = implode('.', array_slice($segments, 1));
6209  return array(null, $group, $item);
6210  }
6211  }
6212  protected function parseNamespacedSegments($key)
6213  {
6214  list($namespace, $item) = explode('::', $key);
6215  $itemSegments = explode('.', $item);
6216  $groupAndItem = array_slice($this->parseBasicSegments($itemSegments), 1);
6217  return array_merge(array($namespace), $groupAndItem);
6218  }
6219  public function setParsedKey($key, $parsed)
6220  {
6221  $this->parsed[$key] = $parsed;
6222  }
6223 }
6225 
6226 use FilesystemIterator;
6231 {
6232  use Macroable;
6233  public function exists($path)
6234  {
6235  return file_exists($path);
6236  }
6237  public function get($path)
6238  {
6239  if ($this->isFile($path)) {
6240  return file_get_contents($path);
6241  }
6242  throw new FileNotFoundException("File does not exist at path {$path}");
6243  }
6244  public function getRequire($path)
6245  {
6246  if ($this->isFile($path)) {
6247  return require $path;
6248  }
6249  throw new FileNotFoundException("File does not exist at path {$path}");
6250  }
6251  public function requireOnce($file)
6252  {
6253  require_once $file;
6254  }
6255  public function put($path, $contents, $lock = false)
6256  {
6257  return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);
6258  }
6259  public function prepend($path, $data)
6260  {
6261  if ($this->exists($path)) {
6262  return $this->put($path, $data . $this->get($path));
6263  }
6264  return $this->put($path, $data);
6265  }
6266  public function append($path, $data)
6267  {
6268  return file_put_contents($path, $data, FILE_APPEND);
6269  }
6270  public function delete($paths)
6271  {
6272  $paths = is_array($paths) ? $paths : func_get_args();
6273  $success = true;
6274  foreach ($paths as $path) {
6275  if (!@unlink($path)) {
6276  $success = false;
6277  }
6278  }
6279  return $success;
6280  }
6281  public function move($path, $target)
6282  {
6283  return rename($path, $target);
6284  }
6285  public function copy($path, $target)
6286  {
6287  return copy($path, $target);
6288  }
6289  public function name($path)
6290  {
6291  return pathinfo($path, PATHINFO_FILENAME);
6292  }
6293  public function extension($path)
6294  {
6295  return pathinfo($path, PATHINFO_EXTENSION);
6296  }
6297  public function type($path)
6298  {
6299  return filetype($path);
6300  }
6301  public function mimeType($path)
6302  {
6303  return finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path);
6304  }
6305  public function size($path)
6306  {
6307  return filesize($path);
6308  }
6309  public function lastModified($path)
6310  {
6311  return filemtime($path);
6312  }
6313  public function isDirectory($directory)
6314  {
6315  return is_dir($directory);
6316  }
6317  public function isWritable($path)
6318  {
6319  return is_writable($path);
6320  }
6321  public function isFile($file)
6322  {
6323  return is_file($file);
6324  }
6325  public function glob($pattern, $flags = 0)
6326  {
6327  return glob($pattern, $flags);
6328  }
6329  public function files($directory)
6330  {
6331  $glob = glob($directory . '/*');
6332  if ($glob === false) {
6333  return array();
6334  }
6335  return array_filter($glob, function ($file) {
6336  return filetype($file) == 'file';
6337  });
6338  }
6339  public function allFiles($directory)
6340  {
6341  return iterator_to_array(Finder::create()->files()->in($directory), false);
6342  }
6343  public function directories($directory)
6344  {
6345  $directories = array();
6346  foreach (Finder::create()->in($directory)->directories()->depth(0) as $dir) {
6347  $directories[] = $dir->getPathname();
6348  }
6349  return $directories;
6350  }
6351  public function makeDirectory($path, $mode = 493, $recursive = false, $force = false)
6352  {
6353  if ($force) {
6354  return @mkdir($path, $mode, $recursive);
6355  }
6356  return mkdir($path, $mode, $recursive);
6357  }
6358  public function copyDirectory($directory, $destination, $options = null)
6359  {
6360  if (!$this->isDirectory($directory)) {
6361  return false;
6362  }
6363  $options = $options ?: FilesystemIterator::SKIP_DOTS;
6364  if (!$this->isDirectory($destination)) {
6365  $this->makeDirectory($destination, 511, true);
6366  }
6367  $items = new FilesystemIterator($directory, $options);
6368  foreach ($items as $item) {
6369  $target = $destination . '/' . $item->getBasename();
6370  if ($item->isDir()) {
6371  $path = $item->getPathname();
6372  if (!$this->copyDirectory($path, $target, $options)) {
6373  return false;
6374  }
6375  } else {
6376  if (!$this->copy($item->getPathname(), $target)) {
6377  return false;
6378  }
6379  }
6380  }
6381  return true;
6382  }
6383  public function deleteDirectory($directory, $preserve = false)
6384  {
6385  if (!$this->isDirectory($directory)) {
6386  return false;
6387  }
6388  $items = new FilesystemIterator($directory);
6389  foreach ($items as $item) {
6390  if ($item->isDir() && !$item->isLink()) {
6391  $this->deleteDirectory($item->getPathname());
6392  } else {
6393  $this->delete($item->getPathname());
6394  }
6395  }
6396  if (!$preserve) {
6397  @rmdir($directory);
6398  }
6399  return true;
6400  }
6401  public function cleanDirectory($directory)
6402  {
6403  return $this->deleteDirectory($directory, true);
6404  }
6405 }
6406 namespace Illuminate\Foundation;
6407 
6409 {
6410  protected $aliases;
6411  protected $registered = false;
6412  protected static $instance;
6413  private function __construct($aliases)
6414  {
6415  $this->aliases = $aliases;
6416  }
6417  public static function getInstance(array $aliases = array())
6418  {
6419  if (is_null(static::$instance)) {
6420  return static::$instance = new static($aliases);
6421  }
6422  $aliases = array_merge(static::$instance->getAliases(), $aliases);
6423  static::$instance->setAliases($aliases);
6424  return static::$instance;
6425  }
6426  public function load($alias)
6427  {
6428  if (isset($this->aliases[$alias])) {
6429  return class_alias($this->aliases[$alias], $alias);
6430  }
6431  }
6432  public function alias($class, $alias)
6433  {
6434  $this->aliases[$class] = $alias;
6435  }
6436  public function register()
6437  {
6438  if (!$this->registered) {
6439  $this->prependToLoaderStack();
6440  $this->registered = true;
6441  }
6442  }
6443  protected function prependToLoaderStack()
6444  {
6445  spl_autoload_register(array($this, 'load'), true, true);
6446  }
6447  public function getAliases()
6448  {
6449  return $this->aliases;
6450  }
6451  public function setAliases(array $aliases)
6452  {
6453  $this->aliases = $aliases;
6454  }
6455  public function isRegistered()
6456  {
6457  return $this->registered;
6458  }
6459  public function setRegistered($value)
6460  {
6461  $this->registered = $value;
6462  }
6463  public static function setInstance($loader)
6464  {
6465  static::$instance = $loader;
6466  }
6467  private function __clone()
6468  {
6469  }
6470 }
6471 namespace Illuminate\Foundation;
6472 
6474 use Illuminate\Contracts\Foundation\Application as ApplicationContract;
6476 {
6477  protected $app;
6478  protected $files;
6479  protected $manifestPath;
6480  public function __construct(ApplicationContract $app, Filesystem $files, $manifestPath)
6481  {
6482  $this->app = $app;
6483  $this->files = $files;
6484  $this->manifestPath = $manifestPath;
6485  }
6486  public function load(array $providers)
6487  {
6488  $manifest = $this->loadManifest();
6489  if ($this->shouldRecompile($manifest, $providers)) {
6490  $manifest = $this->compileManifest($providers);
6491  }
6492  foreach ($manifest['when'] as $provider => $events) {
6493  $this->registerLoadEvents($provider, $events);
6494  }
6495  foreach ($manifest['eager'] as $provider) {
6496  $this->app->register($this->createProvider($provider));
6497  }
6498  $this->app->setDeferredServices($manifest['deferred']);
6499  }
6500  protected function registerLoadEvents($provider, array $events)
6501  {
6502  if (count($events) < 1) {
6503  return;
6504  }
6505  $app = $this->app;
6506  $app->make('events')->listen($events, function () use($app, $provider) {
6507  $app->register($provider);
6508  });
6509  }
6510  protected function compileManifest($providers)
6511  {
6512  $manifest = $this->freshManifest($providers);
6513  foreach ($providers as $provider) {
6514  $instance = $this->createProvider($provider);
6515  if ($instance->isDeferred()) {
6516  foreach ($instance->provides() as $service) {
6517  $manifest['deferred'][$service] = $provider;
6518  }
6519  $manifest['when'][$provider] = $instance->when();
6520  } else {
6521  $manifest['eager'][] = $provider;
6522  }
6523  }
6524  return $this->writeManifest($manifest);
6525  }
6526  public function createProvider($provider)
6527  {
6528  return new $provider($this->app);
6529  }
6530  public function shouldRecompile($manifest, $providers)
6531  {
6532  return is_null($manifest) || $manifest['providers'] != $providers;
6533  }
6534  public function loadManifest()
6535  {
6536  if ($this->files->exists($this->manifestPath)) {
6537  $manifest = json_decode($this->files->get($this->manifestPath), true);
6538  return array_merge(array('when' => array()), $manifest);
6539  }
6540  }
6541  public function writeManifest($manifest)
6542  {
6543  $this->files->put($this->manifestPath, json_encode($manifest, JSON_PRETTY_PRINT));
6544  return $manifest;
6545  }
6546  protected function freshManifest(array $providers)
6547  {
6548  return array('providers' => $providers, 'eager' => array(), 'deferred' => array());
6549  }
6550 }
6552 
6555 {
6556  public function register()
6557  {
6558  $this->app->singleton('cookie', function ($app) {
6559  $config = $app['config']['session'];
6560  return (new CookieJar())->setDefaultPathAndDomain($config['path'], $config['domain']);
6561  });
6562  }
6563 }
6565 
6570 {
6571  public function boot()
6572  {
6573  Model::setConnectionResolver($this->app['db']);
6574  Model::setEventDispatcher($this->app['events']);
6575  }
6576  public function register()
6577  {
6578  $this->registerQueueableEntityResolver();
6579  $this->app->singleton('db.factory', function ($app) {
6580  return new ConnectionFactory($app);
6581  });
6582  $this->app->singleton('db', function ($app) {
6583  return new DatabaseManager($app, $app['db.factory']);
6584  });
6585  }
6586  protected function registerQueueableEntityResolver()
6587  {
6588  $this->app->singleton('Illuminate\\Contracts\\Queue\\EntityResolver', function () {
6589  return new Eloquent\QueueEntityResolver();
6590  });
6591  }
6592 }
6594 
6597 {
6598  public function register()
6599  {
6600  $this->app->singleton('encrypter', function ($app) {
6601  $encrypter = new Encrypter($app['config']['app.key']);
6602  if ($app['config']->has('app.cipher')) {
6603  $encrypter->setCipher($app['config']['app.cipher']);
6604  }
6605  return $encrypter;
6606  });
6607  }
6608 }
6609 namespace Illuminate\Filesystem;
6610 
6613 {
6614  public function register()
6615  {
6616  $this->registerNativeFilesystem();
6617  $this->registerFlysystem();
6618  }
6619  protected function registerNativeFilesystem()
6620  {
6621  $this->app->singleton('files', function () {
6622  return new Filesystem();
6623  });
6624  }
6625  protected function registerFlysystem()
6626  {
6627  $this->registerManager();
6628  $this->app->singleton('filesystem.disk', function () {
6629  return $this->app['filesystem']->disk($this->getDefaultDriver());
6630  });
6631  $this->app->singleton('filesystem.cloud', function () {
6632  return $this->app['filesystem']->disk($this->getCloudDriver());
6633  });
6634  }
6635  protected function registerManager()
6636  {
6637  $this->app->singleton('filesystem', function () {
6638  return new FilesystemManager($this->app);
6639  });
6640  }
6641  protected function getDefaultDriver()
6642  {
6643  return $this->app['config']['filesystems.default'];
6644  }
6645  protected function getCloudDriver()
6646  {
6647  return $this->app['config']['filesystems.cloud'];
6648  }
6649 }
6651 
6654 {
6655  public function register()
6656  {
6657  $this->registerSessionManager();
6658  $this->registerSessionDriver();
6659  $this->app->singleton('Illuminate\\Session\\Middleware\\StartSession');
6660  }
6661  protected function registerSessionManager()
6662  {
6663  $this->app->singleton('session', function ($app) {
6664  return new SessionManager($app);
6665  });
6666  }
6667  protected function registerSessionDriver()
6668  {
6669  $this->app->singleton('session.store', function ($app) {
6670  $manager = $app['session'];
6671  return $manager->driver();
6672  });
6673  }
6674 }
6676 
6683 {
6684  public function register()
6685  {
6686  $this->registerEngineResolver();
6687  $this->registerViewFinder();
6688  $this->registerFactory();
6689  }
6690  public function registerEngineResolver()
6691  {
6692  $this->app->singleton('view.engine.resolver', function () {
6693  $resolver = new EngineResolver();
6694  foreach (array('php', 'blade') as $engine) {
6695  $this->{'register' . ucfirst($engine) . 'Engine'}($resolver);
6696  }
6697  return $resolver;
6698  });
6699  }
6700  public function registerPhpEngine($resolver)
6701  {
6702  $resolver->register('php', function () {
6703  return new PhpEngine();
6704  });
6705  }
6706  public function registerBladeEngine($resolver)
6707  {
6708  $app = $this->app;
6709  $app->singleton('blade.compiler', function ($app) {
6710  $cache = $app['config']['view.compiled'];
6711  return new BladeCompiler($app['files'], $cache);
6712  });
6713  $resolver->register('blade', function () use($app) {
6714  return new CompilerEngine($app['blade.compiler'], $app['files']);
6715  });
6716  }
6717  public function registerViewFinder()
6718  {
6719  $this->app->bind('view.finder', function ($app) {
6720  $paths = $app['config']['view.paths'];
6721  return new FileViewFinder($app['files'], $paths);
6722  });
6723  }
6724  public function registerFactory()
6725  {
6726  $this->app->singleton('view', function ($app) {
6727  $resolver = $app['view.engine.resolver'];
6728  $finder = $app['view.finder'];
6729  $env = new Factory($resolver, $finder, $app['events']);
6730  $env->setContainer($app);
6731  $env->share('app', $app);
6732  return $env;
6733  });
6734  }
6735 }
6736 namespace Illuminate\Routing;
6737 
6738 use ReflectionMethod;
6742  protected function callWithDependencies($instance, $method)
6743  {
6744  return call_user_func_array(array($instance, $method), $this->resolveClassMethodDependencies(array(), $instance, $method));
6745  }
6746  protected function resolveClassMethodDependencies(array $parameters, $instance, $method)
6747  {
6748  if (!method_exists($instance, $method)) {
6749  return $parameters;
6750  }
6751  return $this->resolveMethodDependencies($parameters, new ReflectionMethod($instance, $method));
6752  }
6753  public function resolveMethodDependencies(array $parameters, ReflectionFunctionAbstract $reflector)
6754  {
6755  foreach ($reflector->getParameters() as $key => $parameter) {
6756  $class = $parameter->getClass();
6757  if ($class && !$this->alreadyInParameters($class->name, $parameters)) {
6758  array_splice($parameters, $key, 0, array($this->container->make($class->name)));
6759  }
6760  }
6761  return $parameters;
6762  }
6763  protected function alreadyInParameters($class, array $parameters)
6764  {
6765  return !is_null(array_first($parameters, function ($key, $value) use($class) {
6766  return $value instanceof $class;
6767  }));
6768  }
6769 }
6770 namespace Illuminate\Routing;
6771 
6772 use Closure;
6780 use Illuminate\Contracts\Routing\Registrar as RegistrarContract;
6783 class Router implements RegistrarContract
6784 {
6785  use Macroable;
6786  protected $events;
6787  protected $container;
6788  protected $routes;
6789  protected $current;
6790  protected $currentRequest;
6791  protected $middleware = array();
6792  protected $patternFilters = array();
6793  protected $regexFilters = array();
6794  protected $binders = array();
6795  protected $patterns = array();
6796  protected $groupStack = array();
6797  public static $verbs = array('GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS');
6798  public function __construct(Dispatcher $events, Container $container = null)
6799  {
6800  $this->events = $events;
6801  $this->routes = new RouteCollection();
6802  $this->container = $container ?: new Container();
6803  }
6804  public function get($uri, $action)
6805  {
6806  return $this->addRoute(array('GET', 'HEAD'), $uri, $action);
6807  }
6808  public function post($uri, $action)
6809  {
6810  return $this->addRoute('POST', $uri, $action);
6811  }
6812  public function put($uri, $action)
6813  {
6814  return $this->addRoute('PUT', $uri, $action);
6815  }
6816  public function patch($uri, $action)
6817  {
6818  return $this->addRoute('PATCH', $uri, $action);
6819  }
6820  public function delete($uri, $action)
6821  {
6822  return $this->addRoute('DELETE', $uri, $action);
6823  }
6824  public function options($uri, $action)
6825  {
6826  return $this->addRoute('OPTIONS', $uri, $action);
6827  }
6828  public function any($uri, $action)
6829  {
6830  $verbs = array('GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE');
6831  return $this->addRoute($verbs, $uri, $action);
6832  }
6833  public function match($methods, $uri, $action)
6834  {
6835  return $this->addRoute(array_map('strtoupper', (array) $methods), $uri, $action);
6836  }
6837  public function controllers(array $controllers)
6838  {
6839  foreach ($controllers as $uri => $name) {
6840  $this->controller($uri, $name);
6841  }
6842  }
6843  public function controller($uri, $controller, $names = array())
6844  {
6845  $prepended = $controller;
6846  if (!empty($this->groupStack)) {
6847  $prepended = $this->prependGroupUses($controller);
6848  }
6849  $routable = (new ControllerInspector())->getRoutable($prepended, $uri);
6850  foreach ($routable as $method => $routes) {
6851  foreach ($routes as $route) {
6852  $this->registerInspected($route, $controller, $method, $names);
6853  }
6854  }
6855  $this->addFallthroughRoute($controller, $uri);
6856  }
6857  protected function registerInspected($route, $controller, $method, &$names)
6858  {
6859  $action = array('uses' => $controller . '@' . $method);
6860  $action['as'] = array_get($names, $method);
6861  $this->{$route['verb']}($route['uri'], $action);
6862  }
6863  protected function addFallthroughRoute($controller, $uri)
6864  {
6865  $missing = $this->any($uri . '/{_missing}', $controller . '@missingMethod');
6866  $missing->where('_missing', '(.*)');
6867  }
6868  public function resources(array $resources)
6869  {
6870  foreach ($resources as $name => $controller) {
6871  $this->resource($name, $controller);
6872  }
6873  }
6874  public function resource($name, $controller, array $options = array())
6875  {
6876  (new ResourceRegistrar($this))->register($name, $controller, $options);
6877  }
6878  public function group(array $attributes, Closure $callback)
6879  {
6880  $this->updateGroupStack($attributes);
6881  call_user_func($callback, $this);
6882  array_pop($this->groupStack);
6883  }
6884  protected function updateGroupStack(array $attributes)
6885  {
6886  if (!empty($this->groupStack)) {
6887  $attributes = $this->mergeGroup($attributes, last($this->groupStack));
6888  }
6889  $this->groupStack[] = $attributes;
6890  }
6891  public function mergeWithLastGroup($new)
6892  {
6893  return $this->mergeGroup($new, last($this->groupStack));
6894  }
6895  public static function mergeGroup($new, $old)
6896  {
6897  $new['namespace'] = static::formatUsesPrefix($new, $old);
6898  $new['prefix'] = static::formatGroupPrefix($new, $old);
6899  if (isset($new['domain'])) {
6900  unset($old['domain']);
6901  }
6902  $new['where'] = array_merge(array_get($old, 'where', array()), array_get($new, 'where', array()));
6903  return array_merge_recursive(array_except($old, array('namespace', 'prefix', 'where')), $new);
6904  }
6905  protected static function formatUsesPrefix($new, $old)
6906  {
6907  if (isset($new['namespace']) && isset($old['namespace'])) {
6908  return trim(array_get($old, 'namespace'), '\\') . '\\' . trim($new['namespace'], '\\');
6909  } elseif (isset($new['namespace'])) {
6910  return trim($new['namespace'], '\\');
6911  }
6912  return array_get($old, 'namespace');
6913  }
6914  protected static function formatGroupPrefix($new, $old)
6915  {
6916  if (isset($new['prefix'])) {
6917  return trim(array_get($old, 'prefix'), '/') . '/' . trim($new['prefix'], '/');
6918  }
6919  return array_get($old, 'prefix');
6920  }
6921  public function getLastGroupPrefix()
6922  {
6923  if (!empty($this->groupStack)) {
6924  $last = end($this->groupStack);
6925  return isset($last['prefix']) ? $last['prefix'] : '';
6926  }
6927  return '';
6928  }
6929  protected function addRoute($methods, $uri, $action)
6930  {
6931  return $this->routes->add($this->createRoute($methods, $uri, $action));
6932  }
6933  protected function createRoute($methods, $uri, $action)
6934  {
6935  if ($this->actionReferencesController($action)) {
6936  $action = $this->convertToControllerAction($action);
6937  }
6938  $route = $this->newRoute($methods, $this->prefix($uri), $action);
6939  if ($this->hasGroupStack()) {
6940  $this->mergeGroupAttributesIntoRoute($route);
6941  }
6942  $this->addWhereClausesToRoute($route);
6943  return $route;
6944  }
6945  protected function newRoute($methods, $uri, $action)
6946  {
6947  return (new Route($methods, $uri, $action))->setContainer($this->container);
6948  }
6949  protected function prefix($uri)
6950  {
6951  return trim(trim($this->getLastGroupPrefix(), '/') . '/' . trim($uri, '/'), '/') ?: '/';
6952  }
6953  protected function addWhereClausesToRoute($route)
6954  {
6955  $route->where(array_merge($this->patterns, array_get($route->getAction(), 'where', array())));
6956  return $route;
6957  }
6958  protected function mergeGroupAttributesIntoRoute($route)
6959  {
6960  $action = $this->mergeWithLastGroup($route->getAction());
6961  $route->setAction($action);
6962  }
6963  protected function actionReferencesController($action)
6964  {
6965  if ($action instanceof Closure) {
6966  return false;
6967  }
6968  return is_string($action) || is_string(array_get($action, 'uses'));
6969  }
6970  protected function convertToControllerAction($action)
6971  {
6972  if (is_string($action)) {
6973  $action = array('uses' => $action);
6974  }
6975  if (!empty($this->groupStack)) {
6976  $action['uses'] = $this->prependGroupUses($action['uses']);
6977  }
6978  $action['controller'] = $action['uses'];
6979  return $action;
6980  }
6981  protected function prependGroupUses($uses)
6982  {
6983  $group = last($this->groupStack);
6984  return isset($group['namespace']) && strpos($uses, '\\') !== 0 ? $group['namespace'] . '\\' . $uses : $uses;
6985  }
6986  public function dispatch(Request $request)
6987  {
6988  $this->currentRequest = $request;
6989  $response = $this->callFilter('before', $request);
6990  if (is_null($response)) {
6991  $response = $this->dispatchToRoute($request);
6992  }
6993  $response = $this->prepareResponse($request, $response);
6994  $this->callFilter('after', $request, $response);
6995  return $response;
6996  }
6997  public function dispatchToRoute(Request $request)
6998  {
6999  $route = $this->findRoute($request);
7000  $request->setRouteResolver(function () use($route) {
7001  return $route;
7002  });
7003  $this->events->fire('router.matched', array($route, $request));
7004  $response = $this->callRouteBefore($route, $request);
7005  if (is_null($response)) {
7006  $response = $this->runRouteWithinStack($route, $request);
7007  }
7008  $response = $this->prepareResponse($request, $response);
7009  $this->callRouteAfter($route, $request, $response);
7010  return $response;
7011  }
7012  protected function runRouteWithinStack(Route $route, Request $request)
7013  {
7014  $middleware = $this->gatherRouteMiddlewares($route);
7015  return (new Pipeline($this->container))->send($request)->through($middleware)->then(function ($request) use($route) {
7016  return $this->prepareResponse($request, $route->run($request));
7017  });
7018  }
7019  public function gatherRouteMiddlewares(Route $route)
7020  {
7021  return Collection::make($route->middleware())->map(function ($m) {
7022  return Collection::make(array_get($this->middleware, $m, $m));
7023  })->collapse()->all();
7024  }
7025  protected function findRoute($request)
7026  {
7027  $this->current = $route = $this->routes->match($request);
7028  $this->container->instance('Illuminate\\Routing\\Route', $route);
7029  return $this->substituteBindings($route);
7030  }
7031  protected function substituteBindings($route)
7032  {
7033  foreach ($route->parameters() as $key => $value) {
7034  if (isset($this->binders[$key])) {
7035  $route->setParameter($key, $this->performBinding($key, $value, $route));
7036  }
7037  }
7038  return $route;
7039  }
7040  protected function performBinding($key, $value, $route)
7041  {
7042  return call_user_func($this->binders[$key], $value, $route);
7043  }
7044  public function matched($callback)
7045  {
7046  $this->events->listen('router.matched', $callback);
7047  }
7048  public function before($callback)
7049  {
7050  $this->addGlobalFilter('before', $callback);
7051  }
7052  public function after($callback)
7053  {
7054  $this->addGlobalFilter('after', $callback);
7055  }
7056  protected function addGlobalFilter($filter, $callback)
7057  {
7058  $this->events->listen('router.' . $filter, $this->parseFilter($callback));
7059  }
7060  public function getMiddleware()
7061  {
7062  return $this->middleware;
7063  }
7064  public function middleware($name, $class)
7065  {
7066  $this->middleware[$name] = $class;
7067  return $this;
7068  }
7069  public function filter($name, $callback)
7070  {
7071  $this->events->listen('router.filter: ' . $name, $this->parseFilter($callback));
7072  }
7073  protected function parseFilter($callback)
7074  {
7075  if (is_string($callback) && !str_contains($callback, '@')) {
7076  return $callback . '@filter';
7077  }
7078  return $callback;
7079  }
7080  public function when($pattern, $name, $methods = null)
7081  {
7082  if (!is_null($methods)) {
7083  $methods = array_map('strtoupper', (array) $methods);
7084  }
7085  $this->patternFilters[$pattern][] = compact('name', 'methods');
7086  }
7087  public function whenRegex($pattern, $name, $methods = null)
7088  {
7089  if (!is_null($methods)) {
7090  $methods = array_map('strtoupper', (array) $methods);
7091  }
7092  $this->regexFilters[$pattern][] = compact('name', 'methods');
7093  }
7094  public function model($key, $class, Closure $callback = null)
7095  {
7096  $this->bind($key, function ($value) use($class, $callback) {
7097  if (is_null($value)) {
7098  return;
7099  }
7100  if ($model = (new $class())->find($value)) {
7101  return $model;
7102  }
7103  if ($callback instanceof Closure) {
7104  return call_user_func($callback, $value);
7105  }
7106  throw new NotFoundHttpException();
7107  });
7108  }
7109  public function bind($key, $binder)
7110  {
7111  if (is_string($binder)) {
7112  $binder = $this->createClassBinding($binder);
7113  }
7114  $this->binders[str_replace('-', '_', $key)] = $binder;
7115  }
7116  public function createClassBinding($binding)
7117  {
7118  return function ($value, $route) use($binding) {
7119  $segments = explode('@', $binding);
7120  $method = count($segments) == 2 ? $segments[1] : 'bind';
7121  $callable = array($this->container->make($segments[0]), $method);
7122  return call_user_func($callable, $value, $route);
7123  };
7124  }
7125  public function pattern($key, $pattern)
7126  {
7127  $this->patterns[$key] = $pattern;
7128  }
7129  public function patterns($patterns)
7130  {
7131  foreach ($patterns as $key => $pattern) {
7132  $this->pattern($key, $pattern);
7133  }
7134  }
7135  protected function callFilter($filter, $request, $response = null)
7136  {
7137  return $this->events->until('router.' . $filter, array($request, $response));
7138  }
7139  public function callRouteBefore($route, $request)
7140  {
7141  $response = $this->callPatternFilters($route, $request);
7142  return $response ?: $this->callAttachedBefores($route, $request);
7143  }
7144  protected function callPatternFilters($route, $request)
7145  {
7146  foreach ($this->findPatternFilters($request) as $filter => $parameters) {
7147  $response = $this->callRouteFilter($filter, $parameters, $route, $request);
7148  if (!is_null($response)) {
7149  return $response;
7150  }
7151  }
7152  }
7153  public function findPatternFilters($request)
7154  {
7155  $results = array();
7156  list($path, $method) = array($request->path(), $request->getMethod());
7157  foreach ($this->patternFilters as $pattern => $filters) {
7158  if (str_is($pattern, $path)) {
7159  $merge = $this->patternsByMethod($method, $filters);
7160  $results = array_merge($results, $merge);
7161  }
7162  }
7163  foreach ($this->regexFilters as $pattern => $filters) {
7164  if (preg_match($pattern, $path)) {
7165  $merge = $this->patternsByMethod($method, $filters);
7166  $results = array_merge($results, $merge);
7167  }
7168  }
7169  return $results;
7170  }
7171  protected function patternsByMethod($method, $filters)
7172  {
7173  $results = array();
7174  foreach ($filters as $filter) {
7175  if ($this->filterSupportsMethod($filter, $method)) {
7176  $parsed = Route::parseFilters($filter['name']);
7177  $results = array_merge($results, $parsed);
7178  }
7179  }
7180  return $results;
7181  }
7182  protected function filterSupportsMethod($filter, $method)
7183  {
7184  $methods = $filter['methods'];
7185  return is_null($methods) || in_array($method, $methods);
7186  }
7187  protected function callAttachedBefores($route, $request)
7188  {
7189  foreach ($route->beforeFilters() as $filter => $parameters) {
7190  $response = $this->callRouteFilter($filter, $parameters, $route, $request);
7191  if (!is_null($response)) {
7192  return $response;
7193  }
7194  }
7195  }
7196  public function callRouteAfter($route, $request, $response)
7197  {
7198  foreach ($route->afterFilters() as $filter => $parameters) {
7199  $this->callRouteFilter($filter, $parameters, $route, $request, $response);
7200  }
7201  }
7202  public function callRouteFilter($filter, $parameters, $route, $request, $response = null)
7203  {
7204  $data = array_merge(array($route, $request, $response), $parameters);
7205  return $this->events->until('router.filter: ' . $filter, $this->cleanFilterParameters($data));
7206  }
7207  protected function cleanFilterParameters(array $parameters)
7208  {
7209  return array_filter($parameters, function ($p) {
7210  return !is_null($p) && $p !== '';
7211  });
7212  }
7213  protected function prepareResponse($request, $response)
7214  {
7215  if (!$response instanceof SymfonyResponse) {
7216  $response = new Response($response);
7217  }
7218  return $response->prepare($request);
7219  }
7220  public function hasGroupStack()
7221  {
7222  return !empty($this->groupStack);
7223  }
7224  public function getGroupStack()
7225  {
7226  return $this->groupStack;
7227  }
7228  public function input($key, $default = null)
7229  {
7230  return $this->current()->parameter($key, $default);
7231  }
7232  public function getCurrentRoute()
7233  {
7234  return $this->current();
7235  }
7236  public function current()
7237  {
7238  return $this->current;
7239  }
7240  public function has($name)
7241  {
7242  return $this->routes->hasNamedRoute($name);
7243  }
7244  public function currentRouteName()
7245  {
7246  return $this->current() ? $this->current()->getName() : null;
7247  }
7248  public function is()
7249  {
7250  foreach (func_get_args() as $pattern) {
7251  if (str_is($pattern, $this->currentRouteName())) {
7252  return true;
7253  }
7254  }
7255  return false;
7256  }
7257  public function currentRouteNamed($name)
7258  {
7259  return $this->current() ? $this->current()->getName() == $name : false;
7260  }
7261  public function currentRouteAction()
7262  {
7263  if (!$this->current()) {
7264  return;
7265  }
7266  $action = $this->current()->getAction();
7267  return isset($action['controller']) ? $action['controller'] : null;
7268  }
7269  public function uses()
7270  {
7271  foreach (func_get_args() as $pattern) {
7272  if (str_is($pattern, $this->currentRouteAction())) {
7273  return true;
7274  }
7275  }
7276  return false;
7277  }
7278  public function currentRouteUses($action)
7279  {
7280  return $this->currentRouteAction() == $action;
7281  }
7282  public function getCurrentRequest()
7283  {
7284  return $this->currentRequest;
7285  }
7286  public function getRoutes()
7287  {
7288  return $this->routes;
7289  }
7290  public function setRoutes(RouteCollection $routes)
7291  {
7292  foreach ($routes as $route) {
7293  $route->setContainer($this->container);
7294  }
7295  $this->routes = $routes;
7296  $this->container->instance('routes', $this->routes);
7297  }
7298  public function getPatterns()
7299  {
7300  return $this->patterns;
7301  }
7302 }
7303 namespace Illuminate\Routing;
7304 
7305 use Closure;
7306 use LogicException;
7307 use ReflectionFunction;
7317 class Route
7318 {
7320  protected $uri;
7321  protected $methods;
7322  protected $action;
7323  protected $defaults = array();
7324  protected $wheres = array();
7325  protected $parameters;
7326  protected $parameterNames;
7327  protected $compiled;
7328  protected $container;
7329  public static $validators;
7330  public function __construct($methods, $uri, $action)
7331  {
7332  $this->uri = $uri;
7333  $this->methods = (array) $methods;
7334  $this->action = $this->parseAction($action);
7335  if (in_array('GET', $this->methods) && !in_array('HEAD', $this->methods)) {
7336  $this->methods[] = 'HEAD';
7337  }
7338  if (isset($this->action['prefix'])) {
7339  $this->prefix($this->action['prefix']);
7340  }
7341  }
7342  public function run(Request $request)
7343  {
7344  $this->container = $this->container ?: new Container();
7345  try {
7346  if (!is_string($this->action['uses'])) {
7347  return $this->runCallable($request);
7348  }
7349  if ($this->customDispatcherIsBound()) {
7350  return $this->runWithCustomDispatcher($request);
7351  }
7352  return $this->runController($request);
7353  } catch (HttpResponseException $e) {
7354  return $e->getResponse();
7355  }
7356  }
7357  protected function runCallable(Request $request)
7358  {
7359  $parameters = $this->resolveMethodDependencies($this->parametersWithoutNulls(), new ReflectionFunction($this->action['uses']));
7360  return call_user_func_array($this->action['uses'], $parameters);
7361  }
7362  protected function runController(Request $request)
7363  {
7364  list($class, $method) = explode('@', $this->action['uses']);
7365  $parameters = $this->resolveClassMethodDependencies($this->parametersWithoutNulls(), $class, $method);
7366  if (!method_exists($instance = $this->container->make($class), $method)) {
7367  throw new NotFoundHttpException();
7368  }
7369  return call_user_func_array(array($instance, $method), $parameters);
7370  }
7371  protected function customDispatcherIsBound()
7372  {
7373  return $this->container->bound('illuminate.route.dispatcher');
7374  }
7375  protected function runWithCustomDispatcher(Request $request)
7376  {
7377  list($class, $method) = explode('@', $this->action['uses']);
7378  $dispatcher = $this->container->make('illuminate.route.dispatcher');
7379  return $dispatcher->dispatch($this, $request, $class, $method);
7380  }
7381  public function matches(Request $request, $includingMethod = true)
7382  {
7383  $this->compileRoute();
7384  foreach ($this->getValidators() as $validator) {
7385  if (!$includingMethod && $validator instanceof MethodValidator) {
7386  continue;
7387  }
7388  if (!$validator->matches($this, $request)) {
7389  return false;
7390  }
7391  }
7392  return true;
7393  }
7394  protected function compileRoute()
7395  {
7396  $optionals = $this->extractOptionalParameters();
7397  $uri = preg_replace('/\\{(\\w+?)\\?\\}/', '{$1}', $this->uri);
7398  $this->compiled = with(new SymfonyRoute($uri, $optionals, $this->wheres, array(), $this->domain() ?: ''))->compile();
7399  }
7400  protected function extractOptionalParameters()
7401  {
7402  preg_match_all('/\\{(\\w+?)\\?\\}/', $this->uri, $matches);
7403  return isset($matches[1]) ? array_fill_keys($matches[1], null) : array();
7404  }
7405  public function middleware()
7406  {
7407  return (array) array_get($this->action, 'middleware', array());
7408  }
7409  public function beforeFilters()
7410  {
7411  if (!isset($this->action['before'])) {
7412  return array();
7413  }
7414  return $this->parseFilters($this->action['before']);
7415  }
7416  public function afterFilters()
7417  {
7418  if (!isset($this->action['after'])) {
7419  return array();
7420  }
7421  return $this->parseFilters($this->action['after']);
7422  }
7423  public static function parseFilters($filters)
7424  {
7425  return array_build(static::explodeFilters($filters), function ($key, $value) {
7426  return Route::parseFilter($value);
7427  });
7428  }
7429  protected static function explodeFilters($filters)
7430  {
7431  if (is_array($filters)) {
7432  return static::explodeArrayFilters($filters);
7433  }
7434  return array_map('trim', explode('|', $filters));
7435  }
7436  protected static function explodeArrayFilters(array $filters)
7437  {
7438  $results = array();
7439  foreach ($filters as $filter) {
7440  $results = array_merge($results, array_map('trim', explode('|', $filter)));
7441  }
7442  return $results;
7443  }
7444  public static function parseFilter($filter)
7445  {
7446  if (!str_contains($filter, ':')) {
7447  return array($filter, array());
7448  }
7449  return static::parseParameterFilter($filter);
7450  }
7451  protected static function parseParameterFilter($filter)
7452  {
7453  list($name, $parameters) = explode(':', $filter, 2);
7454  return array($name, explode(',', $parameters));
7455  }
7456  public function hasParameter($name)
7457  {
7458  return array_key_exists($name, $this->parameters());
7459  }
7460  public function getParameter($name, $default = null)
7461  {
7462  return $this->parameter($name, $default);
7463  }
7464  public function parameter($name, $default = null)
7465  {
7466  return array_get($this->parameters(), $name, $default);
7467  }
7468  public function setParameter($name, $value)
7469  {
7470  $this->parameters();
7471  $this->parameters[$name] = $value;
7472  }
7473  public function forgetParameter($name)
7474  {
7475  $this->parameters();
7476  unset($this->parameters[$name]);
7477  }
7478  public function parameters()
7479  {
7480  if (isset($this->parameters)) {
7481  return array_map(function ($value) {
7482  return is_string($value) ? rawurldecode($value) : $value;
7483  }, $this->parameters);
7484  }
7485  throw new LogicException('Route is not bound.');
7486  }
7487  public function parametersWithoutNulls()
7488  {
7489  return array_filter($this->parameters(), function ($p) {
7490  return !is_null($p);
7491  });
7492  }
7493  public function parameterNames()
7494  {
7495  if (isset($this->parameterNames)) {
7496  return $this->parameterNames;
7497  }
7498  return $this->parameterNames = $this->compileParameterNames();
7499  }
7500  protected function compileParameterNames()
7501  {
7502  preg_match_all('/\\{(.*?)\\}/', $this->domain() . $this->uri, $matches);
7503  return array_map(function ($m) {
7504  return trim($m, '?');
7505  }, $matches[1]);
7506  }
7507  public function bind(Request $request)
7508  {
7509  $this->compileRoute();
7510  $this->bindParameters($request);
7511  return $this;
7512  }
7513  public function bindParameters(Request $request)
7514  {
7515  $params = $this->matchToKeys(array_slice($this->bindPathParameters($request), 1));
7516  if (!is_null($this->compiled->getHostRegex())) {
7517  $params = $this->bindHostParameters($request, $params);
7518  }
7519  return $this->parameters = $this->replaceDefaults($params);
7520  }
7521  protected function bindPathParameters(Request $request)
7522  {
7523  preg_match($this->compiled->getRegex(), '/' . $request->decodedPath(), $matches);
7524  return $matches;
7525  }
7526  protected function bindHostParameters(Request $request, $parameters)
7527  {
7528  preg_match($this->compiled->getHostRegex(), $request->getHost(), $matches);
7529  return array_merge($this->matchToKeys(array_slice($matches, 1)), $parameters);
7530  }
7531  protected function matchToKeys(array $matches)
7532  {
7533  if (count($this->parameterNames()) == 0) {
7534  return array();
7535  }
7536  $parameters = array_intersect_key($matches, array_flip($this->parameterNames()));
7537  return array_filter($parameters, function ($value) {
7538  return is_string($value) && strlen($value) > 0;
7539  });
7540  }
7541  protected function replaceDefaults(array $parameters)
7542  {
7543  foreach ($parameters as $key => &$value) {
7544  $value = isset($value) ? $value : array_get($this->defaults, $key);
7545  }
7546  return $parameters;
7547  }
7548  protected function parseAction($action)
7549  {
7550  if (is_callable($action)) {
7551  return array('uses' => $action);
7552  } elseif (!isset($action['uses'])) {
7553  $action['uses'] = $this->findCallable($action);
7554  }
7555  return $action;
7556  }
7557  protected function findCallable(array $action)
7558  {
7559  return array_first($action, function ($key, $value) {
7560  return is_callable($value);
7561  });
7562  }
7563  public static function getValidators()
7564  {
7565  if (isset(static::$validators)) {
7566  return static::$validators;
7567  }
7568  return static::$validators = array(new MethodValidator(), new SchemeValidator(), new HostValidator(), new UriValidator());
7569  }
7570  public function before($filters)
7571  {
7572  return $this->addFilters('before', $filters);
7573  }
7574  public function after($filters)
7575  {
7576  return $this->addFilters('after', $filters);
7577  }
7578  protected function addFilters($type, $filters)
7579  {
7580  $filters = static::explodeFilters($filters);
7581  if (isset($this->action[$type])) {
7582  $existing = static::explodeFilters($this->action[$type]);
7583  $this->action[$type] = array_merge($existing, $filters);
7584  } else {
7585  $this->action[$type] = $filters;
7586  }
7587  return $this;
7588  }
7589  public function defaults($key, $value)
7590  {
7591  $this->defaults[$key] = $value;
7592  return $this;
7593  }
7594  public function where($name, $expression = null)
7595  {
7596  foreach ($this->parseWhere($name, $expression) as $name => $expression) {
7597  $this->wheres[$name] = $expression;
7598  }
7599  return $this;
7600  }
7601  protected function parseWhere($name, $expression)
7602  {
7603  return is_array($name) ? $name : array($name => $expression);
7604  }
7605  protected function whereArray(array $wheres)
7606  {
7607  foreach ($wheres as $name => $expression) {
7608  $this->where($name, $expression);
7609  }
7610  return $this;
7611  }
7612  public function prefix($prefix)
7613  {
7614  $this->uri = trim($prefix, '/') . '/' . trim($this->uri, '/');
7615  return $this;
7616  }
7617  public function getPath()
7618  {
7619  return $this->uri();
7620  }
7621  public function uri()
7622  {
7623  return $this->uri;
7624  }
7625  public function getMethods()
7626  {
7627  return $this->methods();
7628  }
7629  public function methods()
7630  {
7631  return $this->methods;
7632  }
7633  public function httpOnly()
7634  {
7635  return in_array('http', $this->action, true);
7636  }
7637  public function httpsOnly()
7638  {
7639  return $this->secure();
7640  }
7641  public function secure()
7642  {
7643  return in_array('https', $this->action, true);
7644  }
7645  public function domain()
7646  {
7647  return isset($this->action['domain']) ? $this->action['domain'] : null;
7648  }
7649  public function getUri()
7650  {
7651  return $this->uri;
7652  }
7653  public function setUri($uri)
7654  {
7655  $this->uri = $uri;
7656  return $this;
7657  }
7658  public function getPrefix()
7659  {
7660  return isset($this->action['prefix']) ? $this->action['prefix'] : null;
7661  }
7662  public function getName()
7663  {
7664  return isset($this->action['as']) ? $this->action['as'] : null;
7665  }
7666  public function getActionName()
7667  {
7668  return isset($this->action['controller']) ? $this->action['controller'] : 'Closure';
7669  }
7670  public function getAction()
7671  {
7672  return $this->action;
7673  }
7674  public function setAction(array $action)
7675  {
7676  $this->action = $action;
7677  return $this;
7678  }
7679  public function getCompiled()
7680  {
7681  return $this->compiled;
7682  }
7684  {
7685  $this->container = $container;
7686  return $this;
7687  }
7688  public function prepareForSerialization()
7689  {
7690  if ($this->action['uses'] instanceof Closure) {
7691  throw new LogicException("Unable to prepare route [{$this->uri}] for serialization. Uses Closure.");
7692  }
7693  unset($this->container);
7694  unset($this->compiled);
7695  }
7696  public function __get($key)
7697  {
7698  return $this->parameter($key);
7699  }
7700 }
7701 namespace Illuminate\Routing;
7702 
7703 use Countable;
7704 use ArrayIterator;
7705 use IteratorAggregate;
7710 class RouteCollection implements Countable, IteratorAggregate
7711 {
7712  protected $routes = array();
7713  protected $allRoutes = array();
7714  protected $nameList = array();
7715  protected $actionList = array();
7716  public function add(Route $route)
7717  {
7718  $this->addToCollections($route);
7719  $this->addLookups($route);
7720  return $route;
7721  }
7722  protected function addToCollections($route)
7723  {
7724  $domainAndUri = $route->domain() . $route->getUri();
7725  foreach ($route->methods() as $method) {
7726  $this->routes[$method][$domainAndUri] = $route;
7727  }
7728  $this->allRoutes[$method . $domainAndUri] = $route;
7729  }
7730  protected function addLookups($route)
7731  {
7732  $action = $route->getAction();
7733  if (isset($action['as'])) {
7734  $this->nameList[$action['as']] = $route;
7735  }
7736  if (isset($action['controller'])) {
7737  $this->addToActionList($action, $route);
7738  }
7739  }
7740  protected function addToActionList($action, $route)
7741  {
7742  $this->actionList[$action['controller']] = $route;
7743  }
7744  public function match(Request $request)
7745  {
7746  $routes = $this->get($request->getMethod());
7747  $route = $this->check($routes, $request);
7748  if (!is_null($route)) {
7749  return $route->bind($request);
7750  }
7751  $others = $this->checkForAlternateVerbs($request);
7752  if (count($others) > 0) {
7753  return $this->getRouteForMethods($request, $others);
7754  }
7755  throw new NotFoundHttpException();
7756  }
7757  protected function checkForAlternateVerbs($request)
7758  {
7759  $methods = array_diff(Router::$verbs, array($request->getMethod()));
7760  $others = array();
7761  foreach ($methods as $method) {
7762  if (!is_null($this->check($this->get($method), $request, false))) {
7763  $others[] = $method;
7764  }
7765  }
7766  return $others;
7767  }
7768  protected function getRouteForMethods($request, array $methods)
7769  {
7770  if ($request->method() == 'OPTIONS') {
7771  return (new Route('OPTIONS', $request->path(), function () use($methods) {
7772  return new Response('', 200, array('Allow' => implode(',', $methods)));
7773  }))->bind($request);
7774  }
7775  $this->methodNotAllowed($methods);
7776  }
7777  protected function methodNotAllowed(array $others)
7778  {
7779  throw new MethodNotAllowedHttpException($others);
7780  }
7781  protected function check(array $routes, $request, $includingMethod = true)
7782  {
7783  return array_first($routes, function ($key, $value) use($request, $includingMethod) {
7784  return $value->matches($request, $includingMethod);
7785  });
7786  }
7787  protected function get($method = null)
7788  {
7789  if (is_null($method)) {
7790  return $this->getRoutes();
7791  }
7792  return array_get($this->routes, $method, array());
7793  }
7794  public function hasNamedRoute($name)
7795  {
7796  return !is_null($this->getByName($name));
7797  }
7798  public function getByName($name)
7799  {
7800  return isset($this->nameList[$name]) ? $this->nameList[$name] : null;
7801  }
7802  public function getByAction($action)
7803  {
7804  return isset($this->actionList[$action]) ? $this->actionList[$action] : null;
7805  }
7806  public function getRoutes()
7807  {
7808  return array_values($this->allRoutes);
7809  }
7810  public function getIterator()
7811  {
7812  return new ArrayIterator($this->getRoutes());
7813  }
7814  public function count()
7815  {
7816  return count($this->getRoutes());
7817  }
7818 }
7820 
7821 class CompiledRoute implements \Serializable
7822 {
7823  private $variables;
7824  private $tokens;
7825  private $staticPrefix;
7826  private $regex;
7827  private $pathVariables;
7828  private $hostVariables;
7829  private $hostRegex;
7830  private $hostTokens;
7831  public function __construct($staticPrefix, $regex, array $tokens, array $pathVariables, $hostRegex = null, array $hostTokens = array(), array $hostVariables = array(), array $variables = array())
7832  {
7833  $this->staticPrefix = (string) $staticPrefix;
7834  $this->regex = $regex;
7835  $this->tokens = $tokens;
7836  $this->pathVariables = $pathVariables;
7837  $this->hostRegex = $hostRegex;
7838  $this->hostTokens = $hostTokens;
7839  $this->hostVariables = $hostVariables;
7840  $this->variables = $variables;
7841  }
7842  public function serialize()
7843  {
7844  return serialize(array('vars' => $this->variables, 'path_prefix' => $this->staticPrefix, 'path_regex' => $this->regex, 'path_tokens' => $this->tokens, 'path_vars' => $this->pathVariables, 'host_regex' => $this->hostRegex, 'host_tokens' => $this->hostTokens, 'host_vars' => $this->hostVariables));
7845  }
7846  public function unserialize($serialized)
7847  {
7848  $data = unserialize($serialized);
7849  $this->variables = $data['vars'];
7850  $this->staticPrefix = $data['path_prefix'];
7851  $this->regex = $data['path_regex'];
7852  $this->tokens = $data['path_tokens'];
7853  $this->pathVariables = $data['path_vars'];
7854  $this->hostRegex = $data['host_regex'];
7855  $this->hostTokens = $data['host_tokens'];
7856  $this->hostVariables = $data['host_vars'];
7857  }
7858  public function getStaticPrefix()
7859  {
7860  return $this->staticPrefix;
7861  }
7862  public function getRegex()
7863  {
7864  return $this->regex;
7865  }
7866  public function getHostRegex()
7867  {
7868  return $this->hostRegex;
7869  }
7870  public function getTokens()
7871  {
7872  return $this->tokens;
7873  }
7874  public function getHostTokens()
7875  {
7876  return $this->hostTokens;
7877  }
7878  public function getVariables()
7879  {
7880  return $this->variables;
7881  }
7882  public function getPathVariables()
7883  {
7884  return $this->pathVariables;
7885  }
7886  public function getHostVariables()
7887  {
7888  return $this->hostVariables;
7889  }
7890 }
7891 namespace Symfony\Component\Routing;
7892 
7894 {
7895  public static function compile(Route $route);
7896 }
7897 namespace Symfony\Component\Routing;
7898 
7900 {
7901  const REGEX_DELIMITER = '#';
7902  const SEPARATORS = '/,;.:-_~+*=@|';
7903  public static function compile(Route $route)
7904  {
7905  $hostVariables = array();
7906  $variables = array();
7907  $hostRegex = null;
7908  $hostTokens = array();
7909  if ('' !== ($host = $route->getHost())) {
7910  $result = self::compilePattern($route, $host, true);
7911  $hostVariables = $result['variables'];
7912  $variables = $hostVariables;
7913  $hostTokens = $result['tokens'];
7914  $hostRegex = $result['regex'];
7915  }
7916  $path = $route->getPath();
7917  $result = self::compilePattern($route, $path, false);
7918  $staticPrefix = $result['staticPrefix'];
7919  $pathVariables = $result['variables'];
7920  $variables = array_merge($variables, $pathVariables);
7921  $tokens = $result['tokens'];
7922  $regex = $result['regex'];
7923  return new CompiledRoute($staticPrefix, $regex, $tokens, $pathVariables, $hostRegex, $hostTokens, $hostVariables, array_unique($variables));
7924  }
7925  private static function compilePattern(Route $route, $pattern, $isHost)
7926  {
7927  $tokens = array();
7928  $variables = array();
7929  $matches = array();
7930  $pos = 0;
7931  $defaultSeparator = $isHost ? '.' : '/';
7932  preg_match_all('#\\{\\w+\\}#', $pattern, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
7933  foreach ($matches as $match) {
7934  $varName = substr($match[0][0], 1, -1);
7935  $precedingText = substr($pattern, $pos, $match[0][1] - $pos);
7936  $pos = $match[0][1] + strlen($match[0][0]);
7937  $precedingChar = strlen($precedingText) > 0 ? substr($precedingText, -1) : '';
7938  $isSeparator = '' !== $precedingChar && false !== strpos(static::SEPARATORS, $precedingChar);
7939  if (is_numeric($varName)) {
7940  throw new \DomainException(sprintf('Variable name "%s" cannot be numeric in route pattern "%s". Please use a different name.', $varName, $pattern));
7941  }
7942  if (in_array($varName, $variables)) {
7943  throw new \LogicException(sprintf('Route pattern "%s" cannot reference variable name "%s" more than once.', $pattern, $varName));
7944  }
7945  if ($isSeparator && strlen($precedingText) > 1) {
7946  $tokens[] = array('text', substr($precedingText, 0, -1));
7947  } elseif (!$isSeparator && strlen($precedingText) > 0) {
7948  $tokens[] = array('text', $precedingText);
7949  }
7950  $regexp = $route->getRequirement($varName);
7951  if (null === $regexp) {
7952  $followingPattern = (string) substr($pattern, $pos);
7953  $nextSeparator = self::findNextSeparator($followingPattern);
7954  $regexp = sprintf('[^%s%s]+', preg_quote($defaultSeparator, self::REGEX_DELIMITER), $defaultSeparator !== $nextSeparator && '' !== $nextSeparator ? preg_quote($nextSeparator, self::REGEX_DELIMITER) : '');
7955  if ('' !== $nextSeparator && !preg_match('#^\\{\\w+\\}#', $followingPattern) || '' === $followingPattern) {
7956  $regexp .= '+';
7957  }
7958  }
7959  $tokens[] = array('variable', $isSeparator ? $precedingChar : '', $regexp, $varName);
7960  $variables[] = $varName;
7961  }
7962  if ($pos < strlen($pattern)) {
7963  $tokens[] = array('text', substr($pattern, $pos));
7964  }
7965  $firstOptional = PHP_INT_MAX;
7966  if (!$isHost) {
7967  for ($i = count($tokens) - 1; $i >= 0; $i--) {
7968  $token = $tokens[$i];
7969  if ('variable' === $token[0] && $route->hasDefault($token[3])) {
7970  $firstOptional = $i;
7971  } else {
7972  break;
7973  }
7974  }
7975  }
7976  $regexp = '';
7977  for ($i = 0, $nbToken = count($tokens); $i < $nbToken; $i++) {
7978  $regexp .= self::computeRegexp($tokens, $i, $firstOptional);
7979  }
7980  return array('staticPrefix' => 'text' === $tokens[0][0] ? $tokens[0][1] : '', 'regex' => self::REGEX_DELIMITER . '^' . $regexp . '$' . self::REGEX_DELIMITER . 's' . ($isHost ? 'i' : ''), 'tokens' => array_reverse($tokens), 'variables' => $variables);
7981  }
7982  private static function findNextSeparator($pattern)
7983  {
7984  if ('' == $pattern) {
7985  return '';
7986  }
7987  $pattern = preg_replace('#\\{\\w+\\}#', '', $pattern);
7988  return isset($pattern[0]) && false !== strpos(static::SEPARATORS, $pattern[0]) ? $pattern[0] : '';
7989  }
7990  private static function computeRegexp(array $tokens, $index, $firstOptional)
7991  {
7992  $token = $tokens[$index];
7993  if ('text' === $token[0]) {
7994  return preg_quote($token[1], self::REGEX_DELIMITER);
7995  } else {
7996  if (0 === $index && 0 === $firstOptional) {
7997  return sprintf('%s(?P<%s>%s)?', preg_quote($token[1], self::REGEX_DELIMITER), $token[3], $token[2]);
7998  } else {
7999  $regexp = sprintf('%s(?P<%s>%s)', preg_quote($token[1], self::REGEX_DELIMITER), $token[3], $token[2]);
8000  if ($index >= $firstOptional) {
8001  $regexp = "(?:{$regexp}";
8002  $nbTokens = count($tokens);
8003  if ($nbTokens - 1 == $index) {
8004  $regexp .= str_repeat(')?', $nbTokens - $firstOptional - (0 === $firstOptional ? 1 : 0));
8005  }
8006  }
8007  return $regexp;
8008  }
8009  }
8010  }
8011 }
8012 namespace Symfony\Component\Routing;
8013 
8014 class Route implements \Serializable
8015 {
8016  private $path = '/';
8017  private $host = '';
8018  private $schemes = array();
8019  private $methods = array();
8020  private $defaults = array();
8021  private $requirements = array();
8022  private $options = array();
8023  private $compiled;
8024  private $condition = '';
8025  public function __construct($path, array $defaults = array(), array $requirements = array(), array $options = array(), $host = '', $schemes = array(), $methods = array(), $condition = '')
8026  {
8027  $this->setPath($path);
8028  $this->setDefaults($defaults);
8029  $this->setRequirements($requirements);
8030  $this->setOptions($options);
8031  $this->setHost($host);
8032  if ($schemes) {
8033  $this->setSchemes($schemes);
8034  }
8035  if ($methods) {
8036  $this->setMethods($methods);
8037  }
8038  $this->setCondition($condition);
8039  }
8040  public function serialize()
8041  {
8042  return serialize(array('path' => $this->path, 'host' => $this->host, 'defaults' => $this->defaults, 'requirements' => $this->requirements, 'options' => $this->options, 'schemes' => $this->schemes, 'methods' => $this->methods, 'condition' => $this->condition, 'compiled' => $this->compiled));
8043  }
8044  public function unserialize($serialized)
8045  {
8046  $data = unserialize($serialized);
8047  $this->path = $data['path'];
8048  $this->host = $data['host'];
8049  $this->defaults = $data['defaults'];
8050  $this->requirements = $data['requirements'];
8051  $this->options = $data['options'];
8052  $this->schemes = $data['schemes'];
8053  $this->methods = $data['methods'];
8054  if (isset($data['condition'])) {
8055  $this->condition = $data['condition'];
8056  }
8057  if (isset($data['compiled'])) {
8058  $this->compiled = $data['compiled'];
8059  }
8060  }
8061  public function getPattern()
8062  {
8063  return $this->path;
8064  }
8065  public function setPattern($pattern)
8066  {
8067  return $this->setPath($pattern);
8068  }
8069  public function getPath()
8070  {
8071  return $this->path;
8072  }
8073  public function setPath($pattern)
8074  {
8075  $this->path = '/' . ltrim(trim($pattern), '/');
8076  $this->compiled = null;
8077  return $this;
8078  }
8079  public function getHost()
8080  {
8081  return $this->host;
8082  }
8083  public function setHost($pattern)
8084  {
8085  $this->host = (string) $pattern;
8086  $this->compiled = null;
8087  return $this;
8088  }
8089  public function getSchemes()
8090  {
8091  return $this->schemes;
8092  }
8093  public function setSchemes($schemes)
8094  {
8095  $this->schemes = array_map('strtolower', (array) $schemes);
8096  if ($this->schemes) {
8097  $this->requirements['_scheme'] = implode('|', $this->schemes);
8098  } else {
8099  unset($this->requirements['_scheme']);
8100  }
8101  $this->compiled = null;
8102  return $this;
8103  }
8104  public function hasScheme($scheme)
8105  {
8106  return in_array(strtolower($scheme), $this->schemes, true);
8107  }
8108  public function getMethods()
8109  {
8110  return $this->methods;
8111  }
8112  public function setMethods($methods)
8113  {
8114  $this->methods = array_map('strtoupper', (array) $methods);
8115  if ($this->methods) {
8116  $this->requirements['_method'] = implode('|', $this->methods);
8117  } else {
8118  unset($this->requirements['_method']);
8119  }
8120  $this->compiled = null;
8121  return $this;
8122  }
8123  public function getOptions()
8124  {
8125  return $this->options;
8126  }
8127  public function setOptions(array $options)
8128  {
8129  $this->options = array('compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler');
8130  return $this->addOptions($options);
8131  }
8132  public function addOptions(array $options)
8133  {
8134  foreach ($options as $name => $option) {
8135  $this->options[$name] = $option;
8136  }
8137  $this->compiled = null;
8138  return $this;
8139  }
8140  public function setOption($name, $value)
8141  {
8142  $this->options[$name] = $value;
8143  $this->compiled = null;
8144  return $this;
8145  }
8146  public function getOption($name)
8147  {
8148  return isset($this->options[$name]) ? $this->options[$name] : null;
8149  }
8150  public function hasOption($name)
8151  {
8152  return array_key_exists($name, $this->options);
8153  }
8154  public function getDefaults()
8155  {
8156  return $this->defaults;
8157  }
8158  public function setDefaults(array $defaults)
8159  {
8160  $this->defaults = array();
8161  return $this->addDefaults($defaults);
8162  }
8163  public function addDefaults(array $defaults)
8164  {
8165  foreach ($defaults as $name => $default) {
8166  $this->defaults[$name] = $default;
8167  }
8168  $this->compiled = null;
8169  return $this;
8170  }
8171  public function getDefault($name)
8172  {
8173  return isset($this->defaults[$name]) ? $this->defaults[$name] : null;
8174  }
8175  public function hasDefault($name)
8176  {
8177  return array_key_exists($name, $this->defaults);
8178  }
8179  public function setDefault($name, $default)
8180  {
8181  $this->defaults[$name] = $default;
8182  $this->compiled = null;
8183  return $this;
8184  }
8185  public function getRequirements()
8186  {
8187  return $this->requirements;
8188  }
8189  public function setRequirements(array $requirements)
8190  {
8191  $this->requirements = array();
8192  return $this->addRequirements($requirements);
8193  }
8194  public function addRequirements(array $requirements)
8195  {
8196  foreach ($requirements as $key => $regex) {
8197  $this->requirements[$key] = $this->sanitizeRequirement($key, $regex);
8198  }
8199  $this->compiled = null;
8200  return $this;
8201  }
8202  public function getRequirement($key)
8203  {
8204  return isset($this->requirements[$key]) ? $this->requirements[$key] : null;
8205  }
8206  public function hasRequirement($key)
8207  {
8208  return array_key_exists($key, $this->requirements);
8209  }
8210  public function setRequirement($key, $regex)
8211  {
8212  $this->requirements[$key] = $this->sanitizeRequirement($key, $regex);
8213  $this->compiled = null;
8214  return $this;
8215  }
8216  public function getCondition()
8217  {
8218  return $this->condition;
8219  }
8220  public function setCondition($condition)
8221  {
8222  $this->condition = (string) $condition;
8223  $this->compiled = null;
8224  return $this;
8225  }
8226  public function compile()
8227  {
8228  if (null !== $this->compiled) {
8229  return $this->compiled;
8230  }
8231  $class = $this->getOption('compiler_class');
8232  return $this->compiled = $class::compile($this);
8233  }
8234  private function sanitizeRequirement($key, $regex)
8235  {
8236  if (!is_string($regex)) {
8237  throw new \InvalidArgumentException(sprintf('Routing requirement for "%s" must be a string.', $key));
8238  }
8239  if ('' !== $regex && '^' === $regex[0]) {
8240  $regex = (string) substr($regex, 1);
8241  }
8242  if ('$' === substr($regex, -1)) {
8243  $regex = substr($regex, 0, -1);
8244  }
8245  if ('' === $regex) {
8246  throw new \InvalidArgumentException(sprintf('Routing requirement for "%s" cannot be empty.', $key));
8247  }
8248  if ('_scheme' === $key) {
8249  $this->setSchemes(explode('|', $regex));
8250  } elseif ('_method' === $key) {
8251  $this->setMethods(explode('|', $regex));
8252  }
8253  return $regex;
8254  }
8255 }
8256 namespace Illuminate\Routing;
8257 
8258 use Closure;
8259 use BadMethodCallException;
8260 use InvalidArgumentException;
8262 abstract class Controller
8263 {
8264  protected $middleware = array();
8265  protected $beforeFilters = array();
8266  protected $afterFilters = array();
8267  protected static $router;
8268  public function middleware($middleware, array $options = array())
8269  {
8270  $this->middleware[$middleware] = $options;
8271  }
8272  public function beforeFilter($filter, array $options = array())
8273  {
8274  $this->beforeFilters[] = $this->parseFilter($filter, $options);
8275  }
8276  public function afterFilter($filter, array $options = array())
8277  {
8278  $this->afterFilters[] = $this->parseFilter($filter, $options);
8279  }
8280  protected function parseFilter($filter, array $options)
8281  {
8282  $parameters = array();
8283  $original = $filter;
8284  if ($filter instanceof Closure) {
8285  $filter = $this->registerClosureFilter($filter);
8286  } elseif ($this->isInstanceFilter($filter)) {
8287  $filter = $this->registerInstanceFilter($filter);
8288  } else {
8289  list($filter, $parameters) = Route::parseFilter($filter);
8290  }
8291  return compact('original', 'filter', 'parameters', 'options');
8292  }
8293  protected function registerClosureFilter(Closure $filter)
8294  {
8295  $this->getRouter()->filter($name = spl_object_hash($filter), $filter);
8296  return $name;
8297  }
8298  protected function registerInstanceFilter($filter)
8299  {
8300  $this->getRouter()->filter($filter, array($this, substr($filter, 1)));
8301  return $filter;
8302  }
8303  protected function isInstanceFilter($filter)
8304  {
8305  if (is_string($filter) && starts_with($filter, '@')) {
8306  if (method_exists($this, substr($filter, 1))) {
8307  return true;
8308  }
8309  throw new InvalidArgumentException("Filter method [{$filter}] does not exist.");
8310  }
8311  return false;
8312  }
8313  public function forgetBeforeFilter($filter)
8314  {
8315  $this->beforeFilters = $this->removeFilter($filter, $this->getBeforeFilters());
8316  }
8317  public function forgetAfterFilter($filter)
8318  {
8319  $this->afterFilters = $this->removeFilter($filter, $this->getAfterFilters());
8320  }
8321  protected function removeFilter($removing, $current)
8322  {
8323  return array_filter($current, function ($filter) use($removing) {
8324  return $filter['original'] != $removing;
8325  });
8326  }
8327  public function getMiddleware()
8328  {
8329  return $this->middleware;
8330  }
8331  public function getBeforeFilters()
8332  {
8333  return $this->beforeFilters;
8334  }
8335  public function getAfterFilters()
8336  {
8337  return $this->afterFilters;
8338  }
8339  public static function getRouter()
8340  {
8341  return static::$router;
8342  }
8343  public static function setRouter(Router $router)
8344  {
8345  static::$router = $router;
8346  }
8347  public function callAction($method, $parameters)
8348  {
8349  return call_user_func_array(array($this, $method), $parameters);
8350  }
8351  public function missingMethod($parameters = array())
8352  {
8353  throw new NotFoundHttpException('Controller method not found.');
8354  }
8355  public function __call($method, $parameters)
8356  {
8357  throw new BadMethodCallException("Method [{$method}] does not exist.");
8358  }
8359 }
8360 namespace Illuminate\Routing;
8361 
8362 use Closure;
8367 {
8369  protected $router;
8370  protected $container;
8371  public function __construct(Router $router, Container $container = null)
8372  {
8373  $this->router = $router;
8374  $this->container = $container;
8375  }
8376  public function dispatch(Route $route, Request $request, $controller, $method)
8377  {
8378  $instance = $this->makeController($controller);
8379  $this->assignAfter($instance, $route, $request, $method);
8380  $response = $this->before($instance, $route, $request, $method);
8381  if (is_null($response)) {
8382  $response = $this->callWithinStack($instance, $route, $request, $method);
8383  }
8384  return $response;
8385  }
8386  protected function makeController($controller)
8387  {
8388  Controller::setRouter($this->router);
8389  return $this->container->make($controller);
8390  }
8391  protected function callWithinStack($instance, $route, $request, $method)
8392  {
8393  $middleware = $this->getMiddleware($instance, $method);
8394  return (new Pipeline($this->container))->send($request)->through($middleware)->then(function ($request) use($instance, $route, $method) {
8395  return $this->call($instance, $route, $method);
8396  });
8397  }
8398  protected function getMiddleware($instance, $method)
8399  {
8400  $middleware = $this->router->getMiddleware();
8401  $results = array();
8402  foreach ($instance->getMiddleware() as $name => $options) {
8403  if (!$this->methodExcludedByOptions($method, $options)) {
8404  $results[] = array_get($middleware, $name, $name);
8405  }
8406  }
8407  return $results;
8408  }
8409  public function methodExcludedByOptions($method, array $options)
8410  {
8411  return !empty($options['only']) && !in_array($method, (array) $options['only']) || !empty($options['except']) && in_array($method, (array) $options['except']);
8412  }
8413  protected function call($instance, $route, $method)
8414  {
8415  $parameters = $this->resolveClassMethodDependencies($route->parametersWithoutNulls(), $instance, $method);
8416  return $instance->callAction($method, $parameters);
8417  }
8418  protected function before($instance, $route, $request, $method)
8419  {
8420  foreach ($instance->getBeforeFilters() as $filter) {
8421  if ($this->filterApplies($filter, $request, $method)) {
8422  $response = $this->callFilter($filter, $route, $request);
8423  if (!is_null($response)) {
8424  return $response;
8425  }
8426  }
8427  }
8428  }
8429  protected function assignAfter($instance, $route, $request, $method)
8430  {
8431  foreach ($instance->getAfterFilters() as $filter) {
8432  if ($this->filterApplies($filter, $request, $method)) {
8433  $route->after($this->getAssignableAfter($filter));
8434  }
8435  }
8436  }
8437  protected function getAssignableAfter($filter)
8438  {
8439  if ($filter['original'] instanceof Closure) {
8440  return $filter['filter'];
8441  }
8442  return $filter['original'];
8443  }
8444  protected function filterApplies($filter, $request, $method)
8445  {
8446  foreach (array('Method', 'On') as $type) {
8447  if ($this->{"filterFails{$type}"}($filter, $request, $method)) {
8448  return false;
8449  }
8450  }
8451  return true;
8452  }
8453  protected function filterFailsMethod($filter, $request, $method)
8454  {
8455  return $this->methodExcludedByOptions($method, $filter['options']);
8456  }
8457  protected function filterFailsOn($filter, $request, $method)
8458  {
8459  $on = array_get($filter, 'options.on');
8460  if (is_null($on)) {
8461  return false;
8462  }
8463  if (is_string($on)) {
8464  $on = explode('|', $on);
8465  }
8466  return !in_array(strtolower($request->getMethod()), $on);
8467  }
8468  protected function callFilter($filter, $route, $request)
8469  {
8470  return $this->router->callRouteFilter($filter['filter'], $filter['parameters'], $route, $request);
8471  }
8472 }
8473 namespace Illuminate\Routing;
8474 
8475 use ReflectionClass;
8476 use ReflectionMethod;
8478 {
8479  protected $verbs = array('any', 'get', 'post', 'put', 'patch', 'delete', 'head', 'options');
8480  public function getRoutable($controller, $prefix)
8481  {
8482  $routable = array();
8483  $reflection = new ReflectionClass($controller);
8484  $methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC);
8485  foreach ($methods as $method) {
8486  if ($this->isRoutable($method)) {
8487  $data = $this->getMethodData($method, $prefix);
8488  $routable[$method->name][] = $data;
8489  if ($data['plain'] == $prefix . '/index') {
8490  $routable[$method->name][] = $this->getIndexData($data, $prefix);
8491  }
8492  }
8493  }
8494  return $routable;
8495  }
8496  public function isRoutable(ReflectionMethod $method)
8497  {
8498  if ($method->class == 'Illuminate\\Routing\\Controller') {
8499  return false;
8500  }
8501  return starts_with($method->name, $this->verbs);
8502  }
8503  public function getMethodData(ReflectionMethod $method, $prefix)
8504  {
8505  $verb = $this->getVerb($name = $method->name);
8506  $uri = $this->addUriWildcards($plain = $this->getPlainUri($name, $prefix));
8507  return compact('verb', 'plain', 'uri');
8508  }
8509  protected function getIndexData($data, $prefix)
8510  {
8511  return array('verb' => $data['verb'], 'plain' => $prefix, 'uri' => $prefix);
8512  }
8513  public function getVerb($name)
8514  {
8515  return head(explode('_', snake_case($name)));
8516  }
8517  public function getPlainUri($name, $prefix)
8518  {
8519  return $prefix . '/' . implode('-', array_slice(explode('_', snake_case($name)), 1));
8520  }
8521  public function addUriWildcards($uri)
8522  {
8523  return $uri . '/{one?}/{two?}/{three?}/{four?}/{five?}';
8524  }
8525 }
8526 namespace Illuminate\Routing;
8527 
8529 use InvalidArgumentException;
8531 use Illuminate\Contracts\Routing\UrlGenerator as UrlGeneratorContract;
8532 class UrlGenerator implements UrlGeneratorContract
8533 {
8534  protected $routes;
8535  protected $request;
8536  protected $forcedRoot;
8537  protected $forceSchema;
8538  protected $cachedRoot;
8539  protected $cachedSchema;
8540  protected $rootNamespace;
8541  protected $sessionResolver;
8542  protected $dontEncode = array('%2F' => '/', '%40' => '@', '%3A' => ':', '%3B' => ';', '%2C' => ',', '%3D' => '=', '%2B' => '+', '%21' => '!', '%2A' => '*', '%7C' => '|', '%3F' => '?', '%26' => '&', '%23' => '#', '%25' => '%');
8543  public function __construct(RouteCollection $routes, Request $request)
8544  {
8545  $this->routes = $routes;
8546  $this->setRequest($request);
8547  }
8548  public function full()
8549  {
8550  return $this->request->fullUrl();
8551  }
8552  public function current()
8553  {
8554  return $this->to($this->request->getPathInfo());
8555  }
8556  public function previous()
8557  {
8558  $referrer = $this->request->headers->get('referer');
8559  $url = $referrer ? $this->to($referrer) : $this->getPreviousUrlFromSession();
8560  return $url ?: $this->to('/');
8561  }
8562  public function to($path, $extra = array(), $secure = null)
8563  {
8564  if ($this->isValidUrl($path)) {
8565  return $path;
8566  }
8567  $scheme = $this->getScheme($secure);
8568  $extra = $this->formatParameters($extra);
8569  $tail = implode('/', array_map('rawurlencode', (array) $extra));
8570  $root = $this->getRootUrl($scheme);
8571  return $this->trimUrl($root, $path, $tail);
8572  }
8573  public function secure($path, $parameters = array())
8574  {
8575  return $this->to($path, $parameters, true);
8576  }
8577  public function asset($path, $secure = null)
8578  {
8579  if ($this->isValidUrl($path)) {
8580  return $path;
8581  }
8582  $root = $this->getRootUrl($this->getScheme($secure));
8583  return $this->removeIndex($root) . '/' . trim($path, '/');
8584  }
8585  protected function removeIndex($root)
8586  {
8587  $i = 'index.php';
8588  return str_contains($root, $i) ? str_replace('/' . $i, '', $root) : $root;
8589  }
8590  public function secureAsset($path)
8591  {
8592  return $this->asset($path, true);
8593  }
8594  protected function getScheme($secure)
8595  {
8596  if (is_null($secure)) {
8597  if (is_null($this->cachedSchema)) {
8598  $this->cachedSchema = $this->forceSchema ?: $this->request->getScheme() . '://';
8599  }
8600  return $this->cachedSchema;
8601  }
8602  return $secure ? 'https://' : 'http://';
8603  }
8604  public function forceSchema($schema)
8605  {
8606  $this->cachedSchema = null;
8607  $this->forceSchema = $schema . '://';
8608  }
8609  public function route($name, $parameters = array(), $absolute = true)
8610  {
8611  if (!is_null($route = $this->routes->getByName($name))) {
8612  return $this->toRoute($route, $parameters, $absolute);
8613  }
8614  throw new InvalidArgumentException("Route [{$name}] not defined.");
8615  }
8616  protected function toRoute($route, $parameters, $absolute)
8617  {
8618  $parameters = $this->formatParameters($parameters);
8619  $domain = $this->getRouteDomain($route, $parameters);
8620  $uri = strtr(rawurlencode($this->addQueryString($this->trimUrl($root = $this->replaceRoot($route, $domain, $parameters), $this->replaceRouteParameters($route->uri(), $parameters)), $parameters)), $this->dontEncode);
8621  return $absolute ? $uri : '/' . ltrim(str_replace($root, '', $uri), '/');
8622  }
8623  protected function replaceRoot($route, $domain, &$parameters)
8624  {
8625  return $this->replaceRouteParameters($this->getRouteRoot($route, $domain), $parameters);
8626  }
8627  protected function replaceRouteParameters($path, array &$parameters)
8628  {
8629  if (count($parameters)) {
8630  $path = preg_replace_sub('/\\{.*?\\}/', $parameters, $this->replaceNamedParameters($path, $parameters));
8631  }
8632  return trim(preg_replace('/\\{.*?\\?\\}/', '', $path), '/');
8633  }
8634  protected function replaceNamedParameters($path, &$parameters)
8635  {
8636  return preg_replace_callback('/\\{(.*?)\\??\\}/', function ($m) use(&$parameters) {
8637  return isset($parameters[$m[1]]) ? array_pull($parameters, $m[1]) : $m[0];
8638  }, $path);
8639  }
8640  protected function addQueryString($uri, array $parameters)
8641  {
8642  if (!is_null($fragment = parse_url($uri, PHP_URL_FRAGMENT))) {
8643  $uri = preg_replace('/#.*/', '', $uri);
8644  }
8645  $uri .= $this->getRouteQueryString($parameters);
8646  return is_null($fragment) ? $uri : $uri . "#{$fragment}";
8647  }
8648  protected function formatParameters($parameters)
8649  {
8650  return $this->replaceRoutableParameters($parameters);
8651  }
8652  protected function replaceRoutableParameters($parameters = array())
8653  {
8654  $parameters = is_array($parameters) ? $parameters : array($parameters);
8655  foreach ($parameters as $key => $parameter) {
8656  if ($parameter instanceof UrlRoutable) {
8657  $parameters[$key] = $parameter->getRouteKey();
8658  }
8659  }
8660  return $parameters;
8661  }
8662  protected function getRouteQueryString(array $parameters)
8663  {
8664  if (count($parameters) == 0) {
8665  return '';
8666  }
8667  $query = http_build_query($keyed = $this->getStringParameters($parameters));
8668  if (count($keyed) < count($parameters)) {
8669  $query .= '&' . implode('&', $this->getNumericParameters($parameters));
8670  }
8671  return '?' . trim($query, '&');
8672  }
8673  protected function getStringParameters(array $parameters)
8674  {
8675  return array_where($parameters, function ($k, $v) {
8676  return is_string($k);
8677  });
8678  }
8679  protected function getNumericParameters(array $parameters)
8680  {
8681  return array_where($parameters, function ($k, $v) {
8682  return is_numeric($k);
8683  });
8684  }
8685  protected function getRouteDomain($route, &$parameters)
8686  {
8687  return $route->domain() ? $this->formatDomain($route, $parameters) : null;
8688  }
8689  protected function formatDomain($route, &$parameters)
8690  {
8691  return $this->addPortToDomain($this->getDomainAndScheme($route));
8692  }
8693  protected function getDomainAndScheme($route)
8694  {
8695  return $this->getRouteScheme($route) . $route->domain();
8696  }
8697  protected function addPortToDomain($domain)
8698  {
8699  if (in_array($this->request->getPort(), array('80', '443'))) {
8700  return $domain;
8701  }
8702  return $domain . ':' . $this->request->getPort();
8703  }
8704  protected function getRouteRoot($route, $domain)
8705  {
8706  return $this->getRootUrl($this->getRouteScheme($route), $domain);
8707  }
8708  protected function getRouteScheme($route)
8709  {
8710  if ($route->httpOnly()) {
8711  return $this->getScheme(false);
8712  } elseif ($route->httpsOnly()) {
8713  return $this->getScheme(true);
8714  }
8715  return $this->getScheme(null);
8716  }
8717  public function action($action, $parameters = array(), $absolute = true)
8718  {
8719  if ($this->rootNamespace && !(strpos($action, '\\') === 0)) {
8720  $action = $this->rootNamespace . '\\' . $action;
8721  } else {
8722  $action = trim($action, '\\');
8723  }
8724  if (!is_null($route = $this->routes->getByAction($action))) {
8725  return $this->toRoute($route, $parameters, $absolute);
8726  }
8727  throw new InvalidArgumentException("Action {$action} not defined.");
8728  }
8729  protected function getRootUrl($scheme, $root = null)
8730  {
8731  if (is_null($root)) {
8732  if (is_null($this->cachedRoot)) {
8733  $this->cachedRoot = $this->forcedRoot ?: $this->request->root();
8734  }
8735  $root = $this->cachedRoot;
8736  }
8737  $start = starts_with($root, 'http://') ? 'http://' : 'https://';
8738  return preg_replace('~' . $start . '~', $scheme, $root, 1);
8739  }
8740  public function forceRootUrl($root)
8741  {
8742  $this->forcedRoot = rtrim($root, '/');
8743  $this->cachedRoot = null;
8744  }
8745  public function isValidUrl($path)
8746  {
8747  if (starts_with($path, array('#', '//', 'mailto:', 'tel:', 'http://', 'https://'))) {
8748  return true;
8749  }
8750  return filter_var($path, FILTER_VALIDATE_URL) !== false;
8751  }
8752  protected function trimUrl($root, $path, $tail = '')
8753  {
8754  return trim($root . '/' . trim($path . '/' . $tail, '/'), '/');
8755  }
8756  public function getRequest()
8757  {
8758  return $this->request;
8759  }
8760  public function setRequest(Request $request)
8761  {
8762  $this->request = $request;
8763  $this->cachedRoot = null;
8764  $this->cachedSchema = null;
8765  }
8766  public function setRoutes(RouteCollection $routes)
8767  {
8768  $this->routes = $routes;
8769  return $this;
8770  }
8771  protected function getPreviousUrlFromSession()
8772  {
8773  $session = $this->getSession();
8774  return $session ? $session->previousUrl() : null;
8775  }
8776  protected function getSession()
8777  {
8778  return call_user_func($this->sessionResolver ?: function () {
8779  });
8780  }
8781  public function setSessionResolver(callable $sessionResolver)
8782  {
8783  $this->sessionResolver = $sessionResolver;
8784  return $this;
8785  }
8786  public function setRootControllerNamespace($rootNamespace)
8787  {
8788  $this->rootNamespace = $rootNamespace;
8789  return $this;
8790  }
8791 }
8792 namespace Illuminate\Bus;
8793 
8796 {
8797  protected $defer = true;
8798  public function register()
8799  {
8800  $this->app->singleton('Illuminate\\Bus\\Dispatcher', function ($app) {
8801  return new Dispatcher($app, function () use($app) {
8802  return $app['Illuminate\\Contracts\\Queue\\Queue'];
8803  });
8804  });
8805  $this->app->alias('Illuminate\\Bus\\Dispatcher', 'Illuminate\\Contracts\\Bus\\Dispatcher');
8806  $this->app->alias('Illuminate\\Bus\\Dispatcher', 'Illuminate\\Contracts\\Bus\\QueueingDispatcher');
8807  }
8808  public function provides()
8809  {
8810  return array('Illuminate\\Bus\\Dispatcher', 'Illuminate\\Contracts\\Bus\\Dispatcher', 'Illuminate\\Contracts\\Bus\\QueueingDispatcher');
8811  }
8812 }
8813 namespace Illuminate\Bus;
8814 
8815 use Closure;
8816 use ArrayAccess;
8817 use ReflectionClass;
8827 use Illuminate\Contracts\Bus\Dispatcher as DispatcherContract;
8828 class Dispatcher implements DispatcherContract, QueueingDispatcher, HandlerResolver
8829 {
8830  protected $container;
8831  protected $pipeline;
8832  protected $pipes = array();
8833  protected $queueResolver;
8834  protected $mappings = array();
8835  protected $mapper;
8836  public function __construct(Container $container, Closure $queueResolver = null)
8837  {
8838  $this->container = $container;
8839  $this->queueResolver = $queueResolver;
8840  $this->pipeline = new Pipeline($container);
8841  }
8842  public function dispatchFromArray($command, array $array)
8843  {
8844  return $this->dispatch($this->marshalFromArray($command, $array));
8845  }
8846  public function dispatchFrom($command, ArrayAccess $source, array $extras = array())
8847  {
8848  return $this->dispatch($this->marshal($command, $source, $extras));
8849  }
8850  protected function marshalFromArray($command, array $array)
8851  {
8852  return $this->marshal($command, new Collection(), $array);
8853  }
8854  protected function marshal($command, ArrayAccess $source, array $extras = array())
8855  {
8856  $injected = array();
8857  $reflection = new ReflectionClass($command);
8858  if ($constructor = $reflection->getConstructor()) {
8859  $injected = array_map(function ($parameter) use($command, $source, $extras) {
8860  return $this->getParameterValueForCommand($command, $source, $parameter, $extras);
8861  }, $constructor->getParameters());
8862  }
8863  return $reflection->newInstanceArgs($injected);
8864  }
8865  protected function getParameterValueForCommand($command, ArrayAccess $source, ReflectionParameter $parameter, array $extras = array())
8866  {
8867  if (array_key_exists($parameter->name, $extras)) {
8868  return $extras[$parameter->name];
8869  }
8870  if (isset($source[$parameter->name])) {
8871  return $source[$parameter->name];
8872  }
8873  if ($parameter->isDefaultValueAvailable()) {
8874  return $parameter->getDefaultValue();
8875  }
8876  MarshalException::whileMapping($command, $parameter);
8877  }
8878  public function dispatch($command, Closure $afterResolving = null)
8879  {
8880  if ($this->queueResolver && $this->commandShouldBeQueued($command)) {
8881  return $this->dispatchToQueue($command);
8882  } else {
8883  return $this->dispatchNow($command, $afterResolving);
8884  }
8885  }
8886  public function dispatchNow($command, Closure $afterResolving = null)
8887  {
8888  return $this->pipeline->send($command)->through($this->pipes)->then(function ($command) use($afterResolving) {
8889  if ($command instanceof SelfHandling) {
8890  return $this->container->call(array($command, 'handle'));
8891  }
8892  $handler = $this->resolveHandler($command);
8893  if ($afterResolving) {
8894  call_user_func($afterResolving, $handler);
8895  }
8896  return call_user_func(array($handler, $this->getHandlerMethod($command)), $command);
8897  });
8898  }
8899  protected function commandShouldBeQueued($command)
8900  {
8901  if ($command instanceof ShouldBeQueued) {
8902  return true;
8903  }
8904  return (new ReflectionClass($this->getHandlerClass($command)))->implementsInterface('Illuminate\\Contracts\\Queue\\ShouldBeQueued');
8905  }
8906  public function dispatchToQueue($command)
8907  {
8908  $queue = call_user_func($this->queueResolver);
8909  if (!$queue instanceof Queue) {
8910  throw new \RuntimeException('Queue resolver did not return a Queue implementation.');
8911  }
8912  if (method_exists($command, 'queue')) {
8913  $command->queue($queue, $command);
8914  } else {
8915  $queue->push($command);
8916  }
8917  }
8918  public function resolveHandler($command)
8919  {
8920  if ($command instanceof SelfHandling) {
8921  return $command;
8922  }
8923  return $this->container->make($this->getHandlerClass($command));
8924  }
8925  public function getHandlerClass($command)
8926  {
8927  if ($command instanceof SelfHandling) {
8928  return get_class($command);
8929  }
8930  return $this->inflectSegment($command, 0);
8931  }
8932  public function getHandlerMethod($command)
8933  {
8934  if ($command instanceof SelfHandling) {
8935  return 'handle';
8936  }
8937  return $this->inflectSegment($command, 1);
8938  }
8939  protected function inflectSegment($command, $segment)
8940  {
8941  $className = get_class($command);
8942  if (isset($this->mappings[$className])) {
8943  return $this->getMappingSegment($className, $segment);
8944  } elseif ($this->mapper) {
8945  return $this->getMapperSegment($command, $segment);
8946  }
8947  throw new \InvalidArgumentException("No handler registered for command [{$className}]");
8948  }
8949  protected function getMappingSegment($className, $segment)
8950  {
8951  return explode('@', $this->mappings[$className])[$segment];
8952  }
8953  protected function getMapperSegment($command, $segment)
8954  {
8955  return explode('@', call_user_func($this->mapper, $command))[$segment];
8956  }
8957  public function maps(array $commands)
8958  {
8959  $this->mappings = array_merge($this->mappings, $commands);
8960  }
8961  public function mapUsing(Closure $mapper)
8962  {
8963  $this->mapper = $mapper;
8964  }
8965  public static function simpleMapping($command, $commandNamespace, $handlerNamespace)
8966  {
8967  $command = str_replace($commandNamespace, '', get_class($command));
8968  return $handlerNamespace . '\\' . trim($command, '\\') . 'Handler@handle';
8969  }
8970  public function pipeThrough(array $pipes)
8971  {
8972  $this->pipes = $pipes;
8973  return $this;
8974  }
8975 }
8977 
8978 use Closure;
8980 use Illuminate\Contracts\Pipeline\Pipeline as PipelineContract;
8981 class Pipeline implements PipelineContract
8982 {
8983  protected $container;
8984  protected $passable;
8985  protected $pipes = array();
8986  protected $method = 'handle';
8988  {
8989  $this->container = $container;
8990  }
8991  public function send($passable)
8992  {
8993  $this->passable = $passable;
8994  return $this;
8995  }
8996  public function through($pipes)
8997  {
8998  $this->pipes = is_array($pipes) ? $pipes : func_get_args();
8999  return $this;
9000  }
9001  public function via($method)
9002  {
9003  $this->method = $method;
9004  return $this;
9005  }
9006  public function then(Closure $destination)
9007  {
9008  $firstSlice = $this->getInitialSlice($destination);
9009  $pipes = array_reverse($this->pipes);
9010  return call_user_func(array_reduce($pipes, $this->getSlice(), $firstSlice), $this->passable);
9011  }
9012  protected function getSlice()
9013  {
9014  return function ($stack, $pipe) {
9015  return function ($passable) use($stack, $pipe) {
9016  if ($pipe instanceof Closure) {
9017  return call_user_func($pipe, $passable, $stack);
9018  } else {
9019  return $this->container->make($pipe)->{$this->method}($passable, $stack);
9020  }
9021  };
9022  };
9023  }
9024  protected function getInitialSlice(Closure $destination)
9025  {
9026  return function ($passable) use($destination) {
9027  return call_user_func($destination, $passable);
9028  };
9029  }
9030 }
9032 
9036 {
9037  public function matches(Route $route, Request $request);
9038 }
9039 namespace Illuminate\Routing\Matching;
9040 
9044 {
9045  public function matches(Route $route, Request $request)
9046  {
9047  if (is_null($route->getCompiled()->getHostRegex())) {
9048  return true;
9049  }
9050  return preg_match($route->getCompiled()->getHostRegex(), $request->getHost());
9051  }
9052 }
9053 namespace Illuminate\Routing\Matching;
9054 
9058 {
9059  public function matches(Route $route, Request $request)
9060  {
9061  return in_array($request->getMethod(), $route->methods());
9062  }
9063 }
9064 namespace Illuminate\Routing\Matching;
9065 
9069 {
9070  public function matches(Route $route, Request $request)
9071  {
9072  if ($route->httpOnly()) {
9073  return !$request->secure();
9074  } elseif ($route->secure()) {
9075  return $request->secure();
9076  }
9077  return true;
9078  }
9079 }
9080 namespace Illuminate\Routing\Matching;
9081 
9085 {
9086  public function matches(Route $route, Request $request)
9087  {
9088  $path = $request->path() == '/' ? '/' : '/' . $request->path();
9089  return preg_match($route->getCompiled()->getRegex(), rawurldecode($path));
9090  }
9091 }
9092 namespace Illuminate\Events;
9093 
9094 use Exception;
9095 use ReflectionClass;
9097 use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
9099 class Dispatcher implements DispatcherContract
9100 {
9101  protected $container;
9102  protected $listeners = array();
9103  protected $wildcards = array();
9104  protected $sorted = array();
9105  protected $firing = array();
9106  protected $queueResolver;
9107  public function __construct(ContainerContract $container = null)
9108  {
9109  $this->container = $container ?: new Container();
9110  }
9111  public function listen($events, $listener, $priority = 0)
9112  {
9113  foreach ((array) $events as $event) {
9114  if (str_contains($event, '*')) {
9115  $this->setupWildcardListen($event, $listener);
9116  } else {
9117  $this->listeners[$event][$priority][] = $this->makeListener($listener);
9118  unset($this->sorted[$event]);
9119  }
9120  }
9121  }
9122  protected function setupWildcardListen($event, $listener)
9123  {
9124  $this->wildcards[$event][] = $this->makeListener($listener);
9125  }
9126  public function hasListeners($eventName)
9127  {
9128  return isset($this->listeners[$eventName]);
9129  }
9130  public function push($event, $payload = array())
9131  {
9132  $this->listen($event . '_pushed', function () use($event, $payload) {
9133  $this->fire($event, $payload);
9134  });
9135  }
9136  public function subscribe($subscriber)
9137  {
9138  $subscriber = $this->resolveSubscriber($subscriber);
9139  $subscriber->subscribe($this);
9140  }
9141  protected function resolveSubscriber($subscriber)
9142  {
9143  if (is_string($subscriber)) {
9144  return $this->container->make($subscriber);
9145  }
9146  return $subscriber;
9147  }
9148  public function until($event, $payload = array())
9149  {
9150  return $this->fire($event, $payload, true);
9151  }
9152  public function flush($event)
9153  {
9154  $this->fire($event . '_pushed');
9155  }
9156  public function firing()
9157  {
9158  return last($this->firing);
9159  }
9160  public function fire($event, $payload = array(), $halt = false)
9161  {
9162  if (is_object($event)) {
9163  list($payload, $event) = array(array($event), get_class($event));
9164  }
9165  $responses = array();
9166  if (!is_array($payload)) {
9167  $payload = array($payload);
9168  }
9169  $this->firing[] = $event;
9170  foreach ($this->getListeners($event) as $listener) {
9171  $response = call_user_func_array($listener, $payload);
9172  if (!is_null($response) && $halt) {
9173  array_pop($this->firing);
9174  return $response;
9175  }
9176  if ($response === false) {
9177  break;
9178  }
9179  $responses[] = $response;
9180  }
9181  array_pop($this->firing);
9182  return $halt ? null : $responses;
9183  }
9184  public function getListeners($eventName)
9185  {
9186  $wildcards = $this->getWildcardListeners($eventName);
9187  if (!isset($this->sorted[$eventName])) {
9188  $this->sortListeners($eventName);
9189  }
9190  return array_merge($this->sorted[$eventName], $wildcards);
9191  }
9192  protected function getWildcardListeners($eventName)
9193  {
9194  $wildcards = array();
9195  foreach ($this->wildcards as $key => $listeners) {
9196  if (str_is($key, $eventName)) {
9197  $wildcards = array_merge($wildcards, $listeners);
9198  }
9199  }
9200  return $wildcards;
9201  }
9202  protected function sortListeners($eventName)
9203  {
9204  $this->sorted[$eventName] = array();
9205  if (isset($this->listeners[$eventName])) {
9206  krsort($this->listeners[$eventName]);
9207  $this->sorted[$eventName] = call_user_func_array('array_merge', $this->listeners[$eventName]);
9208  }
9209  }
9210  public function makeListener($listener)
9211  {
9212  return is_string($listener) ? $this->createClassListener($listener) : $listener;
9213  }
9214  public function createClassListener($listener)
9215  {
9217  return function () use($listener, $container) {
9218  return call_user_func_array($this->createClassCallable($listener, $container), func_get_args());
9219  };
9220  }
9221  protected function createClassCallable($listener, $container)
9222  {
9223  list($class, $method) = $this->parseClassCallable($listener);
9224  if ($this->handlerShouldBeQueued($class)) {
9225  return $this->createQueuedHandlerCallable($class, $method);
9226  } else {
9227  return array($container->make($class), $method);
9228  }
9229  }
9230  protected function parseClassCallable($listener)
9231  {
9232  $segments = explode('@', $listener);
9233  return array($segments[0], count($segments) == 2 ? $segments[1] : 'handle');
9234  }
9235  protected function handlerShouldBeQueued($class)
9236  {
9237  try {
9238  return (new ReflectionClass($class))->implementsInterface('Illuminate\\Contracts\\Queue\\ShouldBeQueued');
9239  } catch (Exception $e) {
9240  return false;
9241  }
9242  }
9243  protected function createQueuedHandlerCallable($class, $method)
9244  {
9245  return function () use($class, $method) {
9246  $arguments = $this->cloneArgumentsForQueueing(func_get_args());
9247  if (method_exists($class, 'queue')) {
9248  $this->callQueueMethodOnHandler($class, $method, $arguments);
9249  } else {
9250  $this->resolveQueue()->push('Illuminate\\Events\\CallQueuedHandler@call', array('class' => $class, 'method' => $method, 'data' => serialize($arguments)));
9251  }
9252  };
9253  }
9254  protected function cloneArgumentsForQueueing(array $arguments)
9255  {
9256  return array_map(function ($a) {
9257  return is_object($a) ? clone $a : $a;
9258  }, $arguments);
9259  }
9260  protected function callQueueMethodOnHandler($class, $method, $arguments)
9261  {
9262  $handler = (new ReflectionClass($class))->newInstanceWithoutConstructor();
9263  $handler->queue($this->resolveQueue(), 'Illuminate\\Events\\CallQueuedHandler@call', array('class' => $class, 'method' => $method, 'data' => serialize($arguments)));
9264  }
9265  public function forget($event)
9266  {
9267  unset($this->listeners[$event], $this->sorted[$event]);
9268  }
9269  public function forgetPushed()
9270  {
9271  foreach ($this->listeners as $key => $value) {
9272  if (ends_with($key, '_pushed')) {
9273  $this->forget($key);
9274  }
9275  }
9276  }
9277  protected function resolveQueue()
9278  {
9279  return call_user_func($this->queueResolver);
9280  }
9281  public function setQueueResolver(callable $resolver)
9282  {
9283  $this->queueResolver = $resolver;
9284  return $this;
9285  }
9286 }
9288 
9289 use DateTime;
9290 use Exception;
9291 use ArrayAccess;
9292 use Carbon\Carbon;
9293 use LogicException;
9294 use JsonSerializable;
9313 abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializable, QueueableEntity, UrlRoutable
9314 {
9315  protected $connection;
9316  protected $table;
9317  protected $primaryKey = 'id';
9318  protected $perPage = 15;
9319  public $incrementing = true;
9320  public $timestamps = true;
9321  protected $attributes = array();
9322  protected $original = array();
9323  protected $relations = array();
9324  protected $hidden = array();
9325  protected $visible = array();
9326  protected $appends = array();
9327  protected $fillable = array();
9328  protected $guarded = array('*');
9329  protected $dates = array();
9330  protected $casts = array();
9331  protected $touches = array();
9332  protected $observables = array();
9333  protected $with = array();
9334  protected $morphClass;
9335  public $exists = false;
9336  public static $snakeAttributes = true;
9337  protected static $resolver;
9338  protected static $dispatcher;
9339  protected static $booted = array();
9340  protected static $globalScopes = array();
9341  protected static $unguarded = false;
9342  protected static $mutatorCache = array();
9343  public static $manyMethods = array('belongsToMany', 'morphToMany', 'morphedByMany');
9344  const CREATED_AT = 'created_at';
9345  const UPDATED_AT = 'updated_at';
9346  public function __construct(array $attributes = array())
9347  {
9348  $this->bootIfNotBooted();
9349  $this->syncOriginal();
9350  $this->fill($attributes);
9351  }
9352  protected function bootIfNotBooted()
9353  {
9354  $class = get_class($this);
9355  if (!isset(static::$booted[$class])) {
9356  static::$booted[$class] = true;
9357  $this->fireModelEvent('booting', false);
9358  static::boot();
9359  $this->fireModelEvent('booted', false);
9360  }
9361  }
9362  protected static function boot()
9363  {
9364  static::bootTraits();
9365  }
9366  protected static function bootTraits()
9367  {
9368  foreach (class_uses_recursive(get_called_class()) as $trait) {
9369  if (method_exists(get_called_class(), $method = 'boot' . class_basename($trait))) {
9370  forward_static_call(array(get_called_class(), $method));
9371  }
9372  }
9373  }
9374  public static function addGlobalScope(ScopeInterface $scope)
9375  {
9376  static::$globalScopes[get_called_class()][get_class($scope)] = $scope;
9377  }
9378  public static function hasGlobalScope($scope)
9379  {
9380  return !is_null(static::getGlobalScope($scope));
9381  }
9382  public static function getGlobalScope($scope)
9383  {
9384  return array_first(static::$globalScopes[get_called_class()], function ($key, $value) use($scope) {
9385  return $scope instanceof $value;
9386  });
9387  }
9388  public function getGlobalScopes()
9389  {
9390  return array_get(static::$globalScopes, get_class($this), array());
9391  }
9392  public static function observe($class)
9393  {
9394  $instance = new static();
9395  $className = is_string($class) ? $class : get_class($class);
9396  foreach ($instance->getObservableEvents() as $event) {
9397  if (method_exists($class, $event)) {
9398  static::registerModelEvent($event, $className . '@' . $event);
9399  }
9400  }
9401  }
9402  public function fill(array $attributes)
9403  {
9404  $totallyGuarded = $this->totallyGuarded();
9405  foreach ($this->fillableFromArray($attributes) as $key => $value) {
9406  $key = $this->removeTableFromKey($key);
9407  if ($this->isFillable($key)) {
9408  $this->setAttribute($key, $value);
9409  } elseif ($totallyGuarded) {
9410  throw new MassAssignmentException($key);
9411  }
9412  }
9413  return $this;
9414  }
9415  public function forceFill(array $attributes)
9416  {
9417  static::unguard();
9418  $this->fill($attributes);
9419  static::reguard();
9420  return $this;
9421  }
9422  protected function fillableFromArray(array $attributes)
9423  {
9424  if (count($this->fillable) > 0 && !static::$unguarded) {
9425  return array_intersect_key($attributes, array_flip($this->fillable));
9426  }
9427  return $attributes;
9428  }
9429  public function newInstance($attributes = array(), $exists = false)
9430  {
9431  $model = new static((array) $attributes);
9432  $model->exists = $exists;
9433  return $model;
9434  }
9435  public function newFromBuilder($attributes = array(), $connection = null)
9436  {
9437  $model = $this->newInstance(array(), true);
9438  $model->setRawAttributes((array) $attributes, true);
9439  $model->setConnection($connection ?: $this->connection);
9440  return $model;
9441  }
9442  public static function hydrate(array $items, $connection = null)
9443  {
9444  $instance = (new static())->setConnection($connection);
9445  $collection = $instance->newCollection($items);
9446  return $collection->map(function ($item) use($instance) {
9447  return $instance->newFromBuilder($item);
9448  });
9449  }
9450  public static function hydrateRaw($query, $bindings = array(), $connection = null)
9451  {
9452  $instance = (new static())->setConnection($connection);
9453  $items = $instance->getConnection()->select($query, $bindings);
9454  return static::hydrate($items, $connection);
9455  }
9456  public static function create(array $attributes)
9457  {
9458  $model = new static($attributes);
9459  $model->save();
9460  return $model;
9461  }
9462  public static function forceCreate(array $attributes)
9463  {
9464  if (static::$unguarded) {
9465  return static::create($attributes);
9466  }
9467  static::unguard();
9468  $model = static::create($attributes);
9469  static::reguard();
9470  return $model;
9471  }
9472  public static function firstOrCreate(array $attributes)
9473  {
9474  if (!is_null($instance = static::where($attributes)->first())) {
9475  return $instance;
9476  }
9477  return static::create($attributes);
9478  }
9479  public static function firstOrNew(array $attributes)
9480  {
9481  if (!is_null($instance = static::where($attributes)->first())) {
9482  return $instance;
9483  }
9484  return new static($attributes);
9485  }
9486  public static function updateOrCreate(array $attributes, array $values = array())
9487  {
9488  $instance = static::firstOrNew($attributes);
9489  $instance->fill($values)->save();
9490  return $instance;
9491  }
9492  protected static function firstByAttributes($attributes)
9493  {
9494  return static::where($attributes)->first();
9495  }
9496  public static function query()
9497  {
9498  return (new static())->newQuery();
9499  }
9500  public static function on($connection = null)
9501  {
9502  $instance = new static();
9503  $instance->setConnection($connection);
9504  return $instance->newQuery();
9505  }
9506  public static function onWriteConnection()
9507  {
9508  $instance = new static();
9509  return $instance->newQuery()->useWritePdo();
9510  }
9511  public static function all($columns = array('*'))
9512  {
9513  $instance = new static();
9514  return $instance->newQuery()->get($columns);
9515  }
9516  public static function find($id, $columns = array('*'))
9517  {
9518  return static::query()->find($id, $columns);
9519  }
9520  public static function findOrNew($id, $columns = array('*'))
9521  {
9522  if (!is_null($model = static::find($id, $columns))) {
9523  return $model;
9524  }
9525  return new static();
9526  }
9527  public function fresh(array $with = array())
9528  {
9529  $key = $this->getKeyName();
9530  return $this->exists ? static::with($with)->where($key, $this->getKey())->first() : null;
9531  }
9532  public function load($relations)
9533  {
9534  if (is_string($relations)) {
9535  $relations = func_get_args();
9536  }
9537  $query = $this->newQuery()->with($relations);
9538  $query->eagerLoadRelations(array($this));
9539  return $this;
9540  }
9541  public static function with($relations)
9542  {
9543  if (is_string($relations)) {
9544  $relations = func_get_args();
9545  }
9546  $instance = new static();
9547  return $instance->newQuery()->with($relations);
9548  }
9549  public function hasOne($related, $foreignKey = null, $localKey = null)
9550  {
9551  $foreignKey = $foreignKey ?: $this->getForeignKey();
9552  $instance = new $related();
9553  $localKey = $localKey ?: $this->getKeyName();
9554  return new HasOne($instance->newQuery(), $this, $instance->getTable() . '.' . $foreignKey, $localKey);
9555  }
9556  public function morphOne($related, $name, $type = null, $id = null, $localKey = null)
9557  {
9558  $instance = new $related();
9559  list($type, $id) = $this->getMorphs($name, $type, $id);
9560  $table = $instance->getTable();
9561  $localKey = $localKey ?: $this->getKeyName();
9562  return new MorphOne($instance->newQuery(), $this, $table . '.' . $type, $table . '.' . $id, $localKey);
9563  }
9564  public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
9565  {
9566  if (is_null($relation)) {
9567  list(, $caller) = debug_backtrace(false, 2);
9568  $relation = $caller['function'];
9569  }
9570  if (is_null($foreignKey)) {
9571  $foreignKey = snake_case($relation) . '_id';
9572  }
9573  $instance = new $related();
9574  $query = $instance->newQuery();
9575  $otherKey = $otherKey ?: $instance->getKeyName();
9576  return new BelongsTo($query, $this, $foreignKey, $otherKey, $relation);
9577  }
9578  public function morphTo($name = null, $type = null, $id = null)
9579  {
9580  if (is_null($name)) {
9581  list(, $caller) = debug_backtrace(false, 2);
9582  $name = snake_case($caller['function']);
9583  }
9584  list($type, $id) = $this->getMorphs($name, $type, $id);
9585  if (is_null($class = $this->{$type})) {
9586  return new MorphTo($this->newQuery(), $this, $id, null, $type, $name);
9587  } else {
9588  $instance = new $class();
9589  return new MorphTo($instance->newQuery(), $this, $id, $instance->getKeyName(), $type, $name);
9590  }
9591  }
9592  public function hasMany($related, $foreignKey = null, $localKey = null)
9593  {
9594  $foreignKey = $foreignKey ?: $this->getForeignKey();
9595  $instance = new $related();
9596  $localKey = $localKey ?: $this->getKeyName();
9597  return new HasMany($instance->newQuery(), $this, $instance->getTable() . '.' . $foreignKey, $localKey);
9598  }
9599  public function hasManyThrough($related, $through, $firstKey = null, $secondKey = null)
9600  {
9601  $through = new $through();
9602  $firstKey = $firstKey ?: $this->getForeignKey();
9603  $secondKey = $secondKey ?: $through->getForeignKey();
9604  return new HasManyThrough((new $related())->newQuery(), $this, $through, $firstKey, $secondKey);
9605  }
9606  public function morphMany($related, $name, $type = null, $id = null, $localKey = null)
9607  {
9608  $instance = new $related();
9609  list($type, $id) = $this->getMorphs($name, $type, $id);
9610  $table = $instance->getTable();
9611  $localKey = $localKey ?: $this->getKeyName();
9612  return new MorphMany($instance->newQuery(), $this, $table . '.' . $type, $table . '.' . $id, $localKey);
9613  }
9614  public function belongsToMany($related, $table = null, $foreignKey = null, $otherKey = null, $relation = null)
9615  {
9616  if (is_null($relation)) {
9617  $relation = $this->getBelongsToManyCaller();
9618  }
9619  $foreignKey = $foreignKey ?: $this->getForeignKey();
9620  $instance = new $related();
9621  $otherKey = $otherKey ?: $instance->getForeignKey();
9622  if (is_null($table)) {
9623  $table = $this->joiningTable($related);
9624  }
9625  $query = $instance->newQuery();
9626  return new BelongsToMany($query, $this, $table, $foreignKey, $otherKey, $relation);
9627  }
9628  public function morphToMany($related, $name, $table = null, $foreignKey = null, $otherKey = null, $inverse = false)
9629  {
9630  $caller = $this->getBelongsToManyCaller();
9631  $foreignKey = $foreignKey ?: $name . '_id';
9632  $instance = new $related();
9633  $otherKey = $otherKey ?: $instance->getForeignKey();
9634  $query = $instance->newQuery();
9635  $table = $table ?: str_plural($name);
9636  return new MorphToMany($query, $this, $name, $table, $foreignKey, $otherKey, $caller, $inverse);
9637  }
9638  public function morphedByMany($related, $name, $table = null, $foreignKey = null, $otherKey = null)
9639  {
9640  $foreignKey = $foreignKey ?: $this->getForeignKey();
9641  $otherKey = $otherKey ?: $name . '_id';
9642  return $this->morphToMany($related, $name, $table, $foreignKey, $otherKey, true);
9643  }
9644  protected function getBelongsToManyCaller()
9645  {
9646  $self = __FUNCTION__;
9647  $caller = array_first(debug_backtrace(false), function ($key, $trace) use($self) {
9648  $caller = $trace['function'];
9649  return !in_array($caller, Model::$manyMethods) && $caller != $self;
9650  });
9651  return !is_null($caller) ? $caller['function'] : null;
9652  }
9653  public function joiningTable($related)
9654  {
9655  $base = snake_case(class_basename($this));
9656  $related = snake_case(class_basename($related));
9657  $models = array($related, $base);
9658  sort($models);
9659  return strtolower(implode('_', $models));
9660  }
9661  public static function destroy($ids)
9662  {
9663  $count = 0;
9664  $ids = is_array($ids) ? $ids : func_get_args();
9665  $instance = new static();
9666  $key = $instance->getKeyName();
9667  foreach ($instance->whereIn($key, $ids)->get() as $model) {
9668  if ($model->delete()) {
9669  $count++;
9670  }
9671  }
9672  return $count;
9673  }
9674  public function delete()
9675  {
9676  if (is_null($this->primaryKey)) {
9677  throw new Exception('No primary key defined on model.');
9678  }
9679  if ($this->exists) {
9680  if ($this->fireModelEvent('deleting') === false) {
9681  return false;
9682  }
9683  $this->touchOwners();
9684  $this->performDeleteOnModel();
9685  $this->exists = false;
9686  $this->fireModelEvent('deleted', false);
9687  return true;
9688  }
9689  }
9690  public function forceDelete()
9691  {
9692  return $this->delete();
9693  }
9694  protected function performDeleteOnModel()
9695  {
9696  $this->setKeysForSaveQuery($this->newQuery())->delete();
9697  }
9698  public static function saving($callback, $priority = 0)
9699  {
9700  static::registerModelEvent('saving', $callback, $priority);
9701  }
9702  public static function saved($callback, $priority = 0)
9703  {
9704  static::registerModelEvent('saved', $callback, $priority);
9705  }
9706  public static function updating($callback, $priority = 0)
9707  {
9708  static::registerModelEvent('updating', $callback, $priority);
9709  }
9710  public static function updated($callback, $priority = 0)
9711  {
9712  static::registerModelEvent('updated', $callback, $priority);
9713  }
9714  public static function creating($callback, $priority = 0)
9715  {
9716  static::registerModelEvent('creating', $callback, $priority);
9717  }
9718  public static function created($callback, $priority = 0)
9719  {
9720  static::registerModelEvent('created', $callback, $priority);
9721  }
9722  public static function deleting($callback, $priority = 0)
9723  {
9724  static::registerModelEvent('deleting', $callback, $priority);
9725  }
9726  public static function deleted($callback, $priority = 0)
9727  {
9728  static::registerModelEvent('deleted', $callback, $priority);
9729  }
9730  public static function flushEventListeners()
9731  {
9732  if (!isset(static::$dispatcher)) {
9733  return;
9734  }
9735  $instance = new static();
9736  foreach ($instance->getObservableEvents() as $event) {
9737  static::$dispatcher->forget("eloquent.{$event}: " . get_called_class());
9738  }
9739  }
9740  protected static function registerModelEvent($event, $callback, $priority = 0)
9741  {
9742  if (isset(static::$dispatcher)) {
9743  $name = get_called_class();
9744  static::$dispatcher->listen("eloquent.{$event}: {$name}", $callback, $priority);
9745  }
9746  }
9747  public function getObservableEvents()
9748  {
9749  return array_merge(array('creating', 'created', 'updating', 'updated', 'deleting', 'deleted', 'saving', 'saved', 'restoring', 'restored'), $this->observables);
9750  }
9751  public function setObservableEvents(array $observables)
9752  {
9753  $this->observables = $observables;
9754  }
9755  public function addObservableEvents($observables)
9756  {
9757  $observables = is_array($observables) ? $observables : func_get_args();
9758  $this->observables = array_unique(array_merge($this->observables, $observables));
9759  }
9760  public function removeObservableEvents($observables)
9761  {
9762  $observables = is_array($observables) ? $observables : func_get_args();
9763  $this->observables = array_diff($this->observables, $observables);
9764  }
9765  protected function increment($column, $amount = 1)
9766  {
9767  return $this->incrementOrDecrement($column, $amount, 'increment');
9768  }
9769  protected function decrement($column, $amount = 1)
9770  {
9771  return $this->incrementOrDecrement($column, $amount, 'decrement');
9772  }
9773  protected function incrementOrDecrement($column, $amount, $method)
9774  {
9775  $query = $this->newQuery();
9776  if (!$this->exists) {
9777  return $query->{$method}($column, $amount);
9778  }
9779  $this->incrementOrDecrementAttributeValue($column, $amount, $method);
9780  return $query->where($this->getKeyName(), $this->getKey())->{$method}($column, $amount);
9781  }
9782  protected function incrementOrDecrementAttributeValue($column, $amount, $method)
9783  {
9784  $this->{$column} = $this->{$column} + ($method == 'increment' ? $amount : $amount * -1);
9785  $this->syncOriginalAttribute($column);
9786  }
9787  public function update(array $attributes = array())
9788  {
9789  if (!$this->exists) {
9790  return $this->newQuery()->update($attributes);
9791  }
9792  return $this->fill($attributes)->save();
9793  }
9794  public function push()
9795  {
9796  if (!$this->save()) {
9797  return false;
9798  }
9799  foreach ($this->relations as $models) {
9800  $models = $models instanceof Collection ? $models->all() : array($models);
9801  foreach (array_filter($models) as $model) {
9802  if (!$model->push()) {
9803  return false;
9804  }
9805  }
9806  }
9807  return true;
9808  }
9809  public function save(array $options = array())
9810  {
9811  $query = $this->newQueryWithoutScopes();
9812  if ($this->fireModelEvent('saving') === false) {
9813  return false;
9814  }
9815  if ($this->exists) {
9816  $saved = $this->performUpdate($query, $options);
9817  } else {
9818  $saved = $this->performInsert($query, $options);
9819  }
9820  if ($saved) {
9821  $this->finishSave($options);
9822  }
9823  return $saved;
9824  }
9825  protected function finishSave(array $options)
9826  {
9827  $this->fireModelEvent('saved', false);
9828  $this->syncOriginal();
9829  if (array_get($options, 'touch', true)) {
9830  $this->touchOwners();
9831  }
9832  }
9833  protected function performUpdate(Builder $query, array $options = array())
9834  {
9835  $dirty = $this->getDirty();
9836  if (count($dirty) > 0) {
9837  if ($this->fireModelEvent('updating') === false) {
9838  return false;
9839  }
9840  if ($this->timestamps && array_get($options, 'timestamps', true)) {
9841  $this->updateTimestamps();
9842  }
9843  $dirty = $this->getDirty();
9844  if (count($dirty) > 0) {
9845  $this->setKeysForSaveQuery($query)->update($dirty);
9846  $this->fireModelEvent('updated', false);
9847  }
9848  }
9849  return true;
9850  }
9851  protected function performInsert(Builder $query, array $options = array())
9852  {
9853  if ($this->fireModelEvent('creating') === false) {
9854  return false;
9855  }
9856  if ($this->timestamps && array_get($options, 'timestamps', true)) {
9857  $this->updateTimestamps();
9858  }
9859  $attributes = $this->attributes;
9860  if ($this->incrementing) {
9861  $this->insertAndSetId($query, $attributes);
9862  } else {
9863  $query->insert($attributes);
9864  }
9865  $this->exists = true;
9866  $this->fireModelEvent('created', false);
9867  return true;
9868  }
9869  protected function insertAndSetId(Builder $query, $attributes)
9870  {
9871  $id = $query->insertGetId($attributes, $keyName = $this->getKeyName());
9872  $this->setAttribute($keyName, $id);
9873  }
9874  public function touchOwners()
9875  {
9876  foreach ($this->touches as $relation) {
9877  $this->{$relation}()->touch();
9878  if (!is_null($this->{$relation})) {
9879  $this->{$relation}->touchOwners();
9880  }
9881  }
9882  }
9883  public function touches($relation)
9884  {
9885  return in_array($relation, $this->touches);
9886  }
9887  protected function fireModelEvent($event, $halt = true)
9888  {
9889  if (!isset(static::$dispatcher)) {
9890  return true;
9891  }
9892  $event = "eloquent.{$event}: " . get_class($this);
9893  $method = $halt ? 'until' : 'fire';
9894  return static::$dispatcher->{$method}($event, $this);
9895  }
9896  protected function setKeysForSaveQuery(Builder $query)
9897  {
9898  $query->where($this->getKeyName(), '=', $this->getKeyForSaveQuery());
9899  return $query;
9900  }
9901  protected function getKeyForSaveQuery()
9902  {
9903  if (isset($this->original[$this->getKeyName()])) {
9904  return $this->original[$this->getKeyName()];
9905  }
9906  return $this->getAttribute($this->getKeyName());
9907  }
9908  public function touch()
9909  {
9910  if (!$this->timestamps) {
9911  return false;
9912  }
9913  $this->updateTimestamps();
9914  return $this->save();
9915  }
9916  protected function updateTimestamps()
9917  {
9918  $time = $this->freshTimestamp();
9919  if (!$this->isDirty(static::UPDATED_AT)) {
9920  $this->setUpdatedAt($time);
9921  }
9922  if (!$this->exists && !$this->isDirty(static::CREATED_AT)) {
9923  $this->setCreatedAt($time);
9924  }
9925  }
9926  public function setCreatedAt($value)
9927  {
9928  $this->{static::CREATED_AT} = $value;
9929  }
9930  public function setUpdatedAt($value)
9931  {
9932  $this->{static::UPDATED_AT} = $value;
9933  }
9934  public function getCreatedAtColumn()
9935  {
9936  return static::CREATED_AT;
9937  }
9938  public function getUpdatedAtColumn()
9939  {
9940  return static::UPDATED_AT;
9941  }
9942  public function freshTimestamp()
9943  {
9944  return new Carbon();
9945  }
9946  public function freshTimestampString()
9947  {
9948  return $this->fromDateTime($this->freshTimestamp());
9949  }
9950  public function newQuery()
9951  {
9952  $builder = $this->newQueryWithoutScopes();
9953  return $this->applyGlobalScopes($builder);
9954  }
9955  public function newQueryWithoutScope($scope)
9956  {
9957  $this->getGlobalScope($scope)->remove($builder = $this->newQuery(), $this);
9958  return $builder;
9959  }
9960  public function newQueryWithoutScopes()
9961  {
9962  $builder = $this->newEloquentBuilder($this->newBaseQueryBuilder());
9963  return $builder->setModel($this)->with($this->with);
9964  }
9965  public function applyGlobalScopes($builder)
9966  {
9967  foreach ($this->getGlobalScopes() as $scope) {
9968  $scope->apply($builder, $this);
9969  }
9970  return $builder;
9971  }
9972  public function removeGlobalScopes($builder)
9973  {
9974  foreach ($this->getGlobalScopes() as $scope) {
9975  $scope->remove($builder, $this);
9976  }
9977  return $builder;
9978  }
9979  public function newEloquentBuilder($query)
9980  {
9981  return new Builder($query);
9982  }
9983  protected function newBaseQueryBuilder()
9984  {
9985  $conn = $this->getConnection();
9986  $grammar = $conn->getQueryGrammar();
9987  return new QueryBuilder($conn, $grammar, $conn->getPostProcessor());
9988  }
9989  public function newCollection(array $models = array())
9990  {
9991  return new Collection($models);
9992  }
9993  public function newPivot(Model $parent, array $attributes, $table, $exists)
9994  {
9995  return new Pivot($parent, $attributes, $table, $exists);
9996  }
9997  public function getTable()
9998  {
9999  if (isset($this->table)) {
10000  return $this->table;
10001  }
10002  return str_replace('\\', '', snake_case(str_plural(class_basename($this))));
10003  }
10004  public function setTable($table)
10005  {
10006  $this->table = $table;
10007  }
10008  public function getKey()
10009  {
10010  return $this->getAttribute($this->getKeyName());
10011  }
10012  public function getQueueableId()
10013  {
10014  return $this->getKey();
10015  }
10016  public function getKeyName()
10017  {
10018  return $this->primaryKey;
10019  }
10020  public function setKeyName($key)
10021  {
10022  $this->primaryKey = $key;
10023  }
10024  public function getQualifiedKeyName()
10025  {
10026  return $this->getTable() . '.' . $this->getKeyName();
10027  }
10028  public function getRouteKey()
10029  {
10030  return $this->getAttribute($this->getRouteKeyName());
10031  }
10032  public function getRouteKeyName()
10033  {
10034  return $this->getKeyName();
10035  }
10036  public function usesTimestamps()
10037  {
10038  return $this->timestamps;
10039  }
10040  protected function getMorphs($name, $type, $id)
10041  {
10042  $type = $type ?: $name . '_type';
10043  $id = $id ?: $name . '_id';
10044  return array($type, $id);
10045  }
10046  public function getMorphClass()
10047  {
10048  return $this->morphClass ?: get_class($this);
10049  }
10050  public function getPerPage()
10051  {
10052  return $this->perPage;
10053  }
10054  public function setPerPage($perPage)
10055  {
10056  $this->perPage = $perPage;
10057  }
10058  public function getForeignKey()
10059  {
10060  return snake_case(class_basename($this)) . '_id';
10061  }
10062  public function getHidden()
10063  {
10064  return $this->hidden;
10065  }
10066  public function setHidden(array $hidden)
10067  {
10068  $this->hidden = $hidden;
10069  }
10070  public function addHidden($attributes = null)
10071  {
10072  $attributes = is_array($attributes) ? $attributes : func_get_args();
10073  $this->hidden = array_merge($this->hidden, $attributes);
10074  }
10075  public function getVisible()
10076  {
10077  return $this->visible;
10078  }
10079  public function setVisible(array $visible)
10080  {
10081  $this->visible = $visible;
10082  }
10083  public function addVisible($attributes = null)
10084  {
10085  $attributes = is_array($attributes) ? $attributes : func_get_args();
10086  $this->visible = array_merge($this->visible, $attributes);
10087  }
10088  public function setAppends(array $appends)
10089  {
10090  $this->appends = $appends;
10091  }
10092  public function getFillable()
10093  {
10094  return $this->fillable;
10095  }
10096  public function fillable(array $fillable)
10097  {
10098  $this->fillable = $fillable;
10099  return $this;
10100  }
10101  public function getGuarded()
10102  {
10103  return $this->guarded;
10104  }
10105  public function guard(array $guarded)
10106  {
10107  $this->guarded = $guarded;
10108  return $this;
10109  }
10110  public static function unguard($state = true)
10111  {
10112  static::$unguarded = $state;
10113  }
10114  public static function reguard()
10115  {
10116  static::$unguarded = false;
10117  }
10118  public static function isUnguarded()
10119  {
10120  return static::$unguarded;
10121  }
10122  public static function unguarded(callable $callback)
10123  {
10124  if (static::$unguarded) {
10125  return $callback();
10126  }
10127  static::unguard();
10128  $result = $callback();
10129  static::reguard();
10130  return $result;
10131  }
10132  public function isFillable($key)
10133  {
10134  if (static::$unguarded) {
10135  return true;
10136  }
10137  if (in_array($key, $this->fillable)) {
10138  return true;
10139  }
10140  if ($this->isGuarded($key)) {
10141  return false;
10142  }
10143  return empty($this->fillable) && !starts_with($key, '_');
10144  }
10145  public function isGuarded($key)
10146  {
10147  return in_array($key, $this->guarded) || $this->guarded == array('*');
10148  }
10149  public function totallyGuarded()
10150  {
10151  return count($this->fillable) == 0 && $this->guarded == array('*');
10152  }
10153  protected function removeTableFromKey($key)
10154  {
10155  if (!str_contains($key, '.')) {
10156  return $key;
10157  }
10158  return last(explode('.', $key));
10159  }
10160  public function getTouchedRelations()
10161  {
10162  return $this->touches;
10163  }
10164  public function setTouchedRelations(array $touches)
10165  {
10166  $this->touches = $touches;
10167  }
10168  public function getIncrementing()
10169  {
10170  return $this->incrementing;
10171  }
10172  public function setIncrementing($value)
10173  {
10174  $this->incrementing = $value;
10175  }
10176  public function toJson($options = 0)
10177  {
10178  return json_encode($this->toArray(), $options);
10179  }
10180  public function jsonSerialize()
10181  {
10182  return $this->toArray();
10183  }
10184  public function toArray()
10185  {
10186  $attributes = $this->attributesToArray();
10187  return array_merge($attributes, $this->relationsToArray());
10188  }
10189  public function attributesToArray()
10190  {
10191  $attributes = $this->getArrayableAttributes();
10192  foreach ($this->getDates() as $key) {
10193  if (!isset($attributes[$key])) {
10194  continue;
10195  }
10196  $attributes[$key] = (string) $this->asDateTime($attributes[$key]);
10197  }
10198  $mutatedAttributes = $this->getMutatedAttributes();
10199  foreach ($mutatedAttributes as $key) {
10200  if (!array_key_exists($key, $attributes)) {
10201  continue;
10202  }
10203  $attributes[$key] = $this->mutateAttributeForArray($key, $attributes[$key]);
10204  }
10205  foreach ($this->casts as $key => $value) {
10206  if (!array_key_exists($key, $attributes) || in_array($key, $mutatedAttributes)) {
10207  continue;
10208  }
10209  $attributes[$key] = $this->castAttribute($key, $attributes[$key]);
10210  }
10211  foreach ($this->getArrayableAppends() as $key) {
10212  $attributes[$key] = $this->mutateAttributeForArray($key, null);
10213  }
10214  return $attributes;
10215  }
10216  protected function getArrayableAttributes()
10217  {
10218  return $this->getArrayableItems($this->attributes);
10219  }
10220  protected function getArrayableAppends()
10221  {
10222  if (!count($this->appends)) {
10223  return array();
10224  }
10225  return $this->getArrayableItems(array_combine($this->appends, $this->appends));
10226  }
10227  public function relationsToArray()
10228  {
10229  $attributes = array();
10230  foreach ($this->getArrayableRelations() as $key => $value) {
10231  if (in_array($key, $this->hidden)) {
10232  continue;
10233  }
10234  if ($value instanceof Arrayable) {
10235  $relation = $value->toArray();
10236  } elseif (is_null($value)) {
10237  $relation = $value;
10238  }
10239  if (static::$snakeAttributes) {
10240  $key = snake_case($key);
10241  }
10242  if (isset($relation) || is_null($value)) {
10243  $attributes[$key] = $relation;
10244  }
10245  unset($relation);
10246  }
10247  return $attributes;
10248  }
10249  protected function getArrayableRelations()
10250  {
10251  return $this->getArrayableItems($this->relations);
10252  }
10253  protected function getArrayableItems(array $values)
10254  {
10255  if (count($this->visible) > 0) {
10256  return array_intersect_key($values, array_flip($this->visible));
10257  }
10258  return array_diff_key($values, array_flip($this->hidden));
10259  }
10260  public function getAttribute($key)
10261  {
10262  $inAttributes = array_key_exists($key, $this->attributes);
10263  if ($inAttributes || $this->hasGetMutator($key)) {
10264  return $this->getAttributeValue($key);
10265  }
10266  if (array_key_exists($key, $this->relations)) {
10267  return $this->relations[$key];
10268  }
10269  if (method_exists($this, $key)) {
10270  return $this->getRelationshipFromMethod($key);
10271  }
10272  }
10273  protected function getAttributeValue($key)
10274  {
10275  $value = $this->getAttributeFromArray($key);
10276  if ($this->hasGetMutator($key)) {
10277  return $this->mutateAttribute($key, $value);
10278  }
10279  if ($this->hasCast($key)) {
10280  $value = $this->castAttribute($key, $value);
10281  } elseif (in_array($key, $this->getDates())) {
10282  if (!is_null($value)) {
10283  return $this->asDateTime($value);
10284  }
10285  }
10286  return $value;
10287  }
10288  protected function getAttributeFromArray($key)
10289  {
10290  if (array_key_exists($key, $this->attributes)) {
10291  return $this->attributes[$key];
10292  }
10293  }
10294  protected function getRelationshipFromMethod($method)
10295  {
10296  $relations = $this->{$method}();
10297  if (!$relations instanceof Relation) {
10298  throw new LogicException('Relationship method must return an object of type ' . 'Illuminate\\Database\\Eloquent\\Relations\\Relation');
10299  }
10300  return $this->relations[$method] = $relations->getResults();
10301  }
10302  public function hasGetMutator($key)
10303  {
10304  return method_exists($this, 'get' . studly_case($key) . 'Attribute');
10305  }
10306  protected function mutateAttribute($key, $value)
10307  {
10308  return $this->{'get' . studly_case($key) . 'Attribute'}($value);
10309  }
10310  protected function mutateAttributeForArray($key, $value)
10311  {
10312  $value = $this->mutateAttribute($key, $value);
10313  return $value instanceof Arrayable ? $value->toArray() : $value;
10314  }
10315  protected function hasCast($key)
10316  {
10317  return array_key_exists($key, $this->casts);
10318  }
10319  protected function isJsonCastable($key)
10320  {
10321  if ($this->hasCast($key)) {
10322  return in_array($this->getCastType($key), array('array', 'json', 'object', 'collection'), true);
10323  }
10324  return false;
10325  }
10326  protected function getCastType($key)
10327  {
10328  return trim(strtolower($this->casts[$key]));
10329  }
10330  protected function castAttribute($key, $value)
10331  {
10332  if (is_null($value)) {
10333  return $value;
10334  }
10335  switch ($this->getCastType($key)) {
10336  case 'int':
10337  case 'integer':
10338  return (int) $value;
10339  case 'real':
10340  case 'float':
10341  case 'double':
10342  return (double) $value;
10343  case 'string':
10344  return (string) $value;
10345  case 'bool':
10346  case 'boolean':
10347  return (bool) $value;
10348  case 'object':
10349  return json_decode($value);
10350  case 'array':
10351  case 'json':
10352  return json_decode($value, true);
10353  case 'collection':
10354  return $this->newCollection(json_decode($value, true));
10355  default:
10356  return $value;
10357  }
10358  }
10359  public function setAttribute($key, $value)
10360  {
10361  if ($this->hasSetMutator($key)) {
10362  $method = 'set' . studly_case($key) . 'Attribute';
10363  return $this->{$method}($value);
10364  } elseif (in_array($key, $this->getDates()) && $value) {
10365  $value = $this->fromDateTime($value);
10366  }
10367  if ($this->isJsonCastable($key)) {
10368  $value = json_encode($value);
10369  }
10370  $this->attributes[$key] = $value;
10371  }
10372  public function hasSetMutator($key)
10373  {
10374  return method_exists($this, 'set' . studly_case($key) . 'Attribute');
10375  }
10376  public function getDates()
10377  {
10378  $defaults = array(static::CREATED_AT, static::UPDATED_AT);
10379  return array_merge($this->dates, $defaults);
10380  }
10381  public function fromDateTime($value)
10382  {
10383  $format = $this->getDateFormat();
10384  if ($value instanceof DateTime) {
10385  } elseif (is_numeric($value)) {
10386  $value = Carbon::createFromTimestamp($value);
10387  } elseif (preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})$/', $value)) {
10388  $value = Carbon::createFromFormat('Y-m-d', $value)->startOfDay();
10389  } else {
10390  $value = Carbon::createFromFormat($format, $value);
10391  }
10392  return $value->format($format);
10393  }
10394  protected function asDateTime($value)
10395  {
10396  if (is_numeric($value)) {
10397  return Carbon::createFromTimestamp($value);
10398  } elseif (preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})$/', $value)) {
10399  return Carbon::createFromFormat('Y-m-d', $value)->startOfDay();
10400  } elseif (!$value instanceof DateTime) {
10401  $format = $this->getDateFormat();
10402  return Carbon::createFromFormat($format, $value);
10403  }
10404  return Carbon::instance($value);
10405  }
10406  protected function getDateFormat()
10407  {
10408  return $this->getConnection()->getQueryGrammar()->getDateFormat();
10409  }
10410  public function replicate(array $except = null)
10411  {
10412  $except = $except ?: array($this->getKeyName(), $this->getCreatedAtColumn(), $this->getUpdatedAtColumn());
10413  $attributes = array_except($this->attributes, $except);
10414  with($instance = new static())->setRawAttributes($attributes);
10415  return $instance->setRelations($this->relations);
10416  }
10417  public function getAttributes()
10418  {
10419  return $this->attributes;
10420  }
10421  public function setRawAttributes(array $attributes, $sync = false)
10422  {
10423  $this->attributes = $attributes;
10424  if ($sync) {
10425  $this->syncOriginal();
10426  }
10427  }
10428  public function getOriginal($key = null, $default = null)
10429  {
10430  return array_get($this->original, $key, $default);
10431  }
10432  public function syncOriginal()
10433  {
10434  $this->original = $this->attributes;
10435  return $this;
10436  }
10437  public function syncOriginalAttribute($attribute)
10438  {
10439  $this->original[$attribute] = $this->attributes[$attribute];
10440  return $this;
10441  }
10442  public function isDirty($attributes = null)
10443  {
10444  $dirty = $this->getDirty();
10445  if (is_null($attributes)) {
10446  return count($dirty) > 0;
10447  }
10448  if (!is_array($attributes)) {
10449  $attributes = func_get_args();
10450  }
10451  foreach ($attributes as $attribute) {
10452  if (array_key_exists($attribute, $dirty)) {
10453  return true;
10454  }
10455  }
10456  return false;
10457  }
10458  public function getDirty()
10459  {
10460  $dirty = array();
10461  foreach ($this->attributes as $key => $value) {
10462  if (!array_key_exists($key, $this->original)) {
10463  $dirty[$key] = $value;
10464  } elseif ($value !== $this->original[$key] && !$this->originalIsNumericallyEquivalent($key)) {
10465  $dirty[$key] = $value;
10466  }
10467  }
10468  return $dirty;
10469  }
10470  protected function originalIsNumericallyEquivalent($key)
10471  {
10472  $current = $this->attributes[$key];
10473  $original = $this->original[$key];
10474  return is_numeric($current) && is_numeric($original) && strcmp((string) $current, (string) $original) === 0;
10475  }
10476  public function getRelations()
10477  {
10478  return $this->relations;
10479  }
10480  public function getRelation($relation)
10481  {
10482  return $this->relations[$relation];
10483  }
10484  public function setRelation($relation, $value)
10485  {
10486  $this->relations[$relation] = $value;
10487  return $this;
10488  }
10489  public function setRelations(array $relations)
10490  {
10491  $this->relations = $relations;
10492  return $this;
10493  }
10494  public function getConnection()
10495  {
10496  return static::resolveConnection($this->connection);
10497  }
10498  public function getConnectionName()
10499  {
10500  return $this->connection;
10501  }
10502  public function setConnection($name)
10503  {
10504  $this->connection = $name;
10505  return $this;
10506  }
10507  public static function resolveConnection($connection = null)
10508  {
10509  return static::$resolver->connection($connection);
10510  }
10511  public static function getConnectionResolver()
10512  {
10513  return static::$resolver;
10514  }
10515  public static function setConnectionResolver(Resolver $resolver)
10516  {
10517  static::$resolver = $resolver;
10518  }
10519  public static function unsetConnectionResolver()
10520  {
10521  static::$resolver = null;
10522  }
10523  public static function getEventDispatcher()
10524  {
10525  return static::$dispatcher;
10526  }
10527  public static function setEventDispatcher(Dispatcher $dispatcher)
10528  {
10529  static::$dispatcher = $dispatcher;
10530  }
10531  public static function unsetEventDispatcher()
10532  {
10533  static::$dispatcher = null;
10534  }
10535  public function getMutatedAttributes()
10536  {
10537  $class = get_class($this);
10538  if (!isset(static::$mutatorCache[$class])) {
10539  static::cacheMutatedAttributes($class);
10540  }
10541  return static::$mutatorCache[$class];
10542  }
10543  public static function cacheMutatedAttributes($class)
10544  {
10545  $mutatedAttributes = array();
10546  foreach (get_class_methods($class) as $method) {
10547  if (strpos($method, 'Attribute') !== false && preg_match('/^get(.+)Attribute$/', $method, $matches)) {
10548  if (static::$snakeAttributes) {
10549  $matches[1] = snake_case($matches[1]);
10550  }
10551  $mutatedAttributes[] = lcfirst($matches[1]);
10552  }
10553  }
10554  static::$mutatorCache[$class] = $mutatedAttributes;
10555  }
10556  public function __get($key)
10557  {
10558  return $this->getAttribute($key);
10559  }
10560  public function __set($key, $value)
10561  {
10562  $this->setAttribute($key, $value);
10563  }
10564  public function offsetExists($offset)
10565  {
10566  return isset($this->{$offset});
10567  }
10568  public function offsetGet($offset)
10569  {
10570  return $this->{$offset};
10571  }
10572  public function offsetSet($offset, $value)
10573  {
10574  $this->{$offset} = $value;
10575  }
10576  public function offsetUnset($offset)
10577  {
10578  unset($this->{$offset});
10579  }
10580  public function __isset($key)
10581  {
10582  return isset($this->attributes[$key]) || isset($this->relations[$key]) || $this->hasGetMutator($key) && !is_null($this->getAttributeValue($key));
10583  }
10584  public function __unset($key)
10585  {
10586  unset($this->attributes[$key], $this->relations[$key]);
10587  }
10588  public function __call($method, $parameters)
10589  {
10590  if (in_array($method, array('increment', 'decrement'))) {
10591  return call_user_func_array(array($this, $method), $parameters);
10592  }
10593  $query = $this->newQuery();
10594  return call_user_func_array(array($query, $method), $parameters);
10595  }
10596  public static function __callStatic($method, $parameters)
10597  {
10598  $instance = new static();
10599  return call_user_func_array(array($instance, $method), $parameters);
10600  }
10601  public function __toString()
10602  {
10603  return $this->toJson();
10604  }
10605  public function __wakeup()
10606  {
10607  $this->bootIfNotBooted();
10608  }
10609 }
10610 namespace Illuminate\Database;
10611 
10613 use InvalidArgumentException;
10616 {
10617  protected $app;
10618  protected $factory;
10619  protected $connections = array();
10620  protected $extensions = array();
10621  public function __construct($app, ConnectionFactory $factory)
10622  {
10623  $this->app = $app;
10624  $this->factory = $factory;
10625  }
10626  public function connection($name = null)
10627  {
10628  list($name, $type) = $this->parseConnectionName($name);
10629  if (!isset($this->connections[$name])) {
10630  $connection = $this->makeConnection($name);
10631  $this->setPdoForType($connection, $type);
10632  $this->connections[$name] = $this->prepare($connection);
10633  }
10634  return $this->connections[$name];
10635  }
10636  protected function parseConnectionName($name)
10637  {
10638  $name = $name ?: $this->getDefaultConnection();
10639  return Str::endsWith($name, array('::read', '::write')) ? explode('::', $name, 2) : array($name, null);
10640  }
10641  public function purge($name = null)
10642  {
10643  $this->disconnect($name);
10644  unset($this->connections[$name]);
10645  }
10646  public function disconnect($name = null)
10647  {
10648  if (isset($this->connections[$name = $name ?: $this->getDefaultConnection()])) {
10649  $this->connections[$name]->disconnect();
10650  }
10651  }
10652  public function reconnect($name = null)
10653  {
10654  $this->disconnect($name = $name ?: $this->getDefaultConnection());
10655  if (!isset($this->connections[$name])) {
10656  return $this->connection($name);
10657  }
10658  return $this->refreshPdoConnections($name);
10659  }
10660  protected function refreshPdoConnections($name)
10661  {
10662  $fresh = $this->makeConnection($name);
10663  return $this->connections[$name]->setPdo($fresh->getPdo())->setReadPdo($fresh->getReadPdo());
10664  }
10665  protected function makeConnection($name)
10666  {
10667  $config = $this->getConfig($name);
10668  if (isset($this->extensions[$name])) {
10669  return call_user_func($this->extensions[$name], $config, $name);
10670  }
10671  $driver = $config['driver'];
10672  if (isset($this->extensions[$driver])) {
10673  return call_user_func($this->extensions[$driver], $config, $name);
10674  }
10675  return $this->factory->make($config, $name);
10676  }
10677  protected function prepare(Connection $connection)
10678  {
10679  $connection->setFetchMode($this->app['config']['database.fetch']);
10680  if ($this->app->bound('events')) {
10681  $connection->setEventDispatcher($this->app['events']);
10682  }
10683  $connection->setReconnector(function ($connection) {
10684  $this->reconnect($connection->getName());
10685  });
10686  return $connection;
10687  }
10688  protected function setPdoForType(Connection $connection, $type = null)
10689  {
10690  if ($type == 'read') {
10691  $connection->setPdo($connection->getReadPdo());
10692  } elseif ($type == 'write') {
10693  $connection->setReadPdo($connection->getPdo());
10694  }
10695  return $connection;
10696  }
10697  protected function getConfig($name)
10698  {
10699  $name = $name ?: $this->getDefaultConnection();
10700  $connections = $this->app['config']['database.connections'];
10701  if (is_null($config = array_get($connections, $name))) {
10702  throw new InvalidArgumentException("Database [{$name}] not configured.");
10703  }
10704  return $config;
10705  }
10706  public function getDefaultConnection()
10707  {
10708  return $this->app['config']['database.default'];
10709  }
10710  public function setDefaultConnection($name)
10711  {
10712  $this->app['config']['database.default'] = $name;
10713  }
10714  public function extend($name, callable $resolver)
10715  {
10716  $this->extensions[$name] = $resolver;
10717  }
10718  public function getConnections()
10719  {
10720  return $this->connections;
10721  }
10722  public function __call($method, $parameters)
10723  {
10724  return call_user_func_array(array($this->connection(), $method), $parameters);
10725  }
10726 }
10727 namespace Illuminate\Database;
10728 
10730 {
10731  public function connection($name = null);
10732  public function getDefaultConnection();
10733  public function setDefaultConnection($name);
10734 }
10736 
10737 use PDO;
10738 use InvalidArgumentException;
10745 {
10746  protected $container;
10748  {
10749  $this->container = $container;
10750  }
10751  public function make(array $config, $name = null)
10752  {
10753  $config = $this->parseConfig($config, $name);
10754  if (isset($config['read'])) {
10755  return $this->createReadWriteConnection($config);
10756  }
10757  return $this->createSingleConnection($config);
10758  }
10759  protected function createSingleConnection(array $config)
10760  {
10761  $pdo = $this->createConnector($config)->connect($config);
10762  return $this->createConnection($config['driver'], $pdo, $config['database'], $config['prefix'], $config);
10763  }
10764  protected function createReadWriteConnection(array $config)
10765  {
10766  $connection = $this->createSingleConnection($this->getWriteConfig($config));
10767  return $connection->setReadPdo($this->createReadPdo($config));
10768  }
10769  protected function createReadPdo(array $config)
10770  {
10771  $readConfig = $this->getReadConfig($config);
10772  return $this->createConnector($readConfig)->connect($readConfig);
10773  }
10774  protected function getReadConfig(array $config)
10775  {
10776  $readConfig = $this->getReadWriteConfig($config, 'read');
10777  return $this->mergeReadWriteConfig($config, $readConfig);
10778  }
10779  protected function getWriteConfig(array $config)
10780  {
10781  $writeConfig = $this->getReadWriteConfig($config, 'write');
10782  return $this->mergeReadWriteConfig($config, $writeConfig);
10783  }
10784  protected function getReadWriteConfig(array $config, $type)
10785  {
10786  if (isset($config[$type][0])) {
10787  return $config[$type][array_rand($config[$type])];
10788  }
10789  return $config[$type];
10790  }
10791  protected function mergeReadWriteConfig(array $config, array $merge)
10792  {
10793  return array_except(array_merge($config, $merge), array('read', 'write'));
10794  }
10795  protected function parseConfig(array $config, $name)
10796  {
10797  return array_add(array_add($config, 'prefix', ''), 'name', $name);
10798  }
10799  public function createConnector(array $config)
10800  {
10801  if (!isset($config['driver'])) {
10802  throw new InvalidArgumentException('A driver must be specified.');
10803  }
10804  if ($this->container->bound($key = "db.connector.{$config['driver']}")) {
10805  return $this->container->make($key);
10806  }
10807  switch ($config['driver']) {
10808  case 'mysql':
10809  return new MySqlConnector();
10810  case 'pgsql':
10811  return new PostgresConnector();
10812  case 'sqlite':
10813  return new SQLiteConnector();
10814  case 'sqlsrv':
10815  return new SqlServerConnector();
10816  }
10817  throw new InvalidArgumentException("Unsupported driver [{$config['driver']}]");
10818  }
10819  protected function createConnection($driver, PDO $connection, $database, $prefix = '', array $config = array())
10820  {
10821  if ($this->container->bound($key = "db.connection.{$driver}")) {
10822  return $this->container->make($key, array($connection, $database, $prefix, $config));
10823  }
10824  switch ($driver) {
10825  case 'mysql':
10826  return new MySqlConnection($connection, $database, $prefix, $config);
10827  case 'pgsql':
10828  return new PostgresConnection($connection, $database, $prefix, $config);
10829  case 'sqlite':
10830  return new SQLiteConnection($connection, $database, $prefix, $config);
10831  case 'sqlsrv':
10832  return new SqlServerConnection($connection, $database, $prefix, $config);
10833  }
10834  throw new InvalidArgumentException("Unsupported driver [{$driver}]");
10835  }
10836 }
10837 namespace Illuminate\Session;
10838 
10841 interface SessionInterface extends BaseSessionInterface
10842 {
10843  public function getHandler();
10844  public function handlerNeedsRequest();
10845  public function setRequestOnHandler(Request $request);
10846 }
10848 
10849 use Closure;
10850 use Carbon\Carbon;
10859 {
10860  protected $manager;
10861  protected $sessionHandled = false;
10862  public function __construct(SessionManager $manager)
10863  {
10864  $this->manager = $manager;
10865  }
10866  public function handle($request, Closure $next)
10867  {
10868  $this->sessionHandled = true;
10869  if ($this->sessionConfigured()) {
10870  $session = $this->startSession($request);
10871  $request->setSession($session);
10872  }
10873  $response = $next($request);
10874  if ($this->sessionConfigured()) {
10875  $this->storeCurrentUrl($request, $session);
10876  $this->collectGarbage($session);
10877  $this->addCookieToResponse($response, $session);
10878  }
10879  return $response;
10880  }
10881  public function terminate($request, $response)
10882  {
10883  if ($this->sessionHandled && $this->sessionConfigured() && !$this->usingCookieSessions()) {
10884  $this->manager->driver()->save();
10885  }
10886  }
10887  protected function startSession(Request $request)
10888  {
10889  with($session = $this->getSession($request))->setRequestOnHandler($request);
10890  $session->start();
10891  return $session;
10892  }
10893  public function getSession(Request $request)
10894  {
10895  $session = $this->manager->driver();
10896  $session->setId($request->cookies->get($session->getName()));
10897  return $session;
10898  }
10899  protected function storeCurrentUrl(Request $request, $session)
10900  {
10901  if ($request->method() === 'GET' && $request->route() && !$request->ajax()) {
10902  $session->setPreviousUrl($request->fullUrl());
10903  }
10904  }
10905  protected function collectGarbage(SessionInterface $session)
10906  {
10907  $config = $this->manager->getSessionConfig();
10908  if ($this->configHitsLottery($config)) {
10909  $session->getHandler()->gc($this->getSessionLifetimeInSeconds());
10910  }
10911  }
10912  protected function configHitsLottery(array $config)
10913  {
10914  return mt_rand(1, $config['lottery'][1]) <= $config['lottery'][0];
10915  }
10917  {
10918  if ($this->usingCookieSessions()) {
10919  $this->manager->driver()->save();
10920  }
10921  if ($this->sessionIsPersistent($config = $this->manager->getSessionConfig())) {
10922  $response->headers->setCookie(new Cookie($session->getName(), $session->getId(), $this->getCookieExpirationDate(), $config['path'], $config['domain'], array_get($config, 'secure', false)));
10923  }
10924  }
10925  protected function getSessionLifetimeInSeconds()
10926  {
10927  return array_get($this->manager->getSessionConfig(), 'lifetime') * 60;
10928  }
10929  protected function getCookieExpirationDate()
10930  {
10931  $config = $this->manager->getSessionConfig();
10932  return $config['expire_on_close'] ? 0 : Carbon::now()->addMinutes($config['lifetime']);
10933  }
10934  protected function sessionConfigured()
10935  {
10936  return !is_null(array_get($this->manager->getSessionConfig(), 'driver'));
10937  }
10938  protected function sessionIsPersistent(array $config = null)
10939  {
10940  $config = $config ?: $this->manager->getSessionConfig();
10941  return !in_array($config['driver'], array(null, 'array'));
10942  }
10943  protected function usingCookieSessions()
10944  {
10945  if (!$this->sessionConfigured()) {
10946  return false;
10947  }
10948  return $this->manager->driver()->getHandler() instanceof CookieSessionHandler;
10949  }
10950 }
10951 namespace Illuminate\Session;
10952 
10954 use InvalidArgumentException;
10958 class Store implements SessionInterface
10959 {
10960  protected $id;
10961  protected $name;
10962  protected $attributes = array();
10963  protected $bags = array();
10964  protected $metaBag;
10965  protected $bagData = array();
10966  protected $handler;
10967  protected $started = false;
10968  public function __construct($name, SessionHandlerInterface $handler, $id = null)
10969  {
10970  $this->setId($id);
10971  $this->name = $name;
10972  $this->handler = $handler;
10973  $this->metaBag = new MetadataBag();
10974  }
10975  public function start()
10976  {
10977  $this->loadSession();
10978  if (!$this->has('_token')) {
10979  $this->regenerateToken();
10980  }
10981  return $this->started = true;
10982  }
10983  protected function loadSession()
10984  {
10985  $this->attributes = array_merge($this->attributes, $this->readFromHandler());
10986  foreach (array_merge($this->bags, array($this->metaBag)) as $bag) {
10987  $this->initializeLocalBag($bag);
10988  $bag->initialize($this->bagData[$bag->getStorageKey()]);
10989  }
10990  }
10991  protected function readFromHandler()
10992  {
10993  $data = $this->handler->read($this->getId());
10994  if ($data) {
10995  $data = @unserialize($this->prepareForUnserialize($data));
10996  if ($data !== false) {
10997  return $data;
10998  }
10999  }
11000  return array();
11001  }
11002  protected function prepareForUnserialize($data)
11003  {
11004  return $data;
11005  }
11006  protected function initializeLocalBag($bag)
11007  {
11008  $this->bagData[$bag->getStorageKey()] = $this->pull($bag->getStorageKey(), array());
11009  }
11010  public function getId()
11011  {
11012  return $this->id;
11013  }
11014  public function setId($id)
11015  {
11016  if (!$this->isValidId($id)) {
11017  $id = $this->generateSessionId();
11018  }
11019  $this->id = $id;
11020  }
11021  public function isValidId($id)
11022  {
11023  return is_string($id) && preg_match('/^[a-f0-9]{40}$/', $id);
11024  }
11025  protected function generateSessionId()
11026  {
11027  return sha1(uniqid('', true) . str_random(25) . microtime(true));
11028  }
11029  public function getName()
11030  {
11031  return $this->name;
11032  }
11033  public function setName($name)
11034  {
11035  $this->name = $name;
11036  }
11037  public function invalidate($lifetime = null)
11038  {
11039  $this->attributes = array();
11040  return $this->migrate();
11041  }
11042  public function migrate($destroy = false, $lifetime = null)
11043  {
11044  if ($destroy) {
11045  $this->handler->destroy($this->getId());
11046  }
11047  $this->setExists(false);
11048  $this->id = $this->generateSessionId();
11049  return true;
11050  }
11051  public function regenerate($destroy = false)
11052  {
11053  return $this->migrate($destroy);
11054  }
11055  public function save()
11056  {
11057  $this->addBagDataToSession();
11058  $this->ageFlashData();
11059  $this->handler->write($this->getId(), $this->prepareForStorage(serialize($this->attributes)));
11060  $this->started = false;
11061  }
11062  protected function prepareForStorage($data)
11063  {
11064  return $data;
11065  }
11066  protected function addBagDataToSession()
11067  {
11068  foreach (array_merge($this->bags, array($this->metaBag)) as $bag) {
11069  $this->put($bag->getStorageKey(), $this->bagData[$bag->getStorageKey()]);
11070  }
11071  }
11072  public function ageFlashData()
11073  {
11074  foreach ($this->get('flash.old', array()) as $old) {
11075  $this->forget($old);
11076  }
11077  $this->put('flash.old', $this->get('flash.new', array()));
11078  $this->put('flash.new', array());
11079  }
11080  public function has($name)
11081  {
11082  return !is_null($this->get($name));
11083  }
11084  public function get($name, $default = null)
11085  {
11086  return array_get($this->attributes, $name, $default);
11087  }
11088  public function pull($key, $default = null)
11089  {
11090  return array_pull($this->attributes, $key, $default);
11091  }
11092  public function hasOldInput($key = null)
11093  {
11094  $old = $this->getOldInput($key);
11095  return is_null($key) ? count($old) > 0 : !is_null($old);
11096  }
11097  public function getOldInput($key = null, $default = null)
11098  {
11099  $input = $this->get('_old_input', array());
11100  return array_get($input, $key, $default);
11101  }
11102  public function set($name, $value)
11103  {
11104  array_set($this->attributes, $name, $value);
11105  }
11106  public function put($key, $value = null)
11107  {
11108  if (!is_array($key)) {
11109  $key = array($key => $value);
11110  }
11111  foreach ($key as $arrayKey => $arrayValue) {
11112  $this->set($arrayKey, $arrayValue);
11113  }
11114  }
11115  public function push($key, $value)
11116  {
11117  $array = $this->get($key, array());
11118  $array[] = $value;
11119  $this->put($key, $array);
11120  }
11121  public function flash($key, $value)
11122  {
11123  $this->put($key, $value);
11124  $this->push('flash.new', $key);
11125  $this->removeFromOldFlashData(array($key));
11126  }
11127  public function flashInput(array $value)
11128  {
11129  $this->flash('_old_input', $value);
11130  }
11131  public function reflash()
11132  {
11133  $this->mergeNewFlashes($this->get('flash.old', array()));
11134  $this->put('flash.old', array());
11135  }
11136  public function keep($keys = null)
11137  {
11138  $keys = is_array($keys) ? $keys : func_get_args();
11139  $this->mergeNewFlashes($keys);
11140  $this->removeFromOldFlashData($keys);
11141  }
11142  protected function mergeNewFlashes(array $keys)
11143  {
11144  $values = array_unique(array_merge($this->get('flash.new', array()), $keys));
11145  $this->put('flash.new', $values);
11146  }
11147  protected function removeFromOldFlashData(array $keys)
11148  {
11149  $this->put('flash.old', array_diff($this->get('flash.old', array()), $keys));
11150  }
11151  public function all()
11152  {
11153  return $this->attributes;
11154  }
11155  public function replace(array $attributes)
11156  {
11157  $this->put($attributes);
11158  }
11159  public function remove($name)
11160  {
11161  return array_pull($this->attributes, $name);
11162  }
11163  public function forget($key)
11164  {
11165  array_forget($this->attributes, $key);
11166  }
11167  public function clear()
11168  {
11169  $this->attributes = array();
11170  foreach ($this->bags as $bag) {
11171  $bag->clear();
11172  }
11173  }
11174  public function flush()
11175  {
11176  $this->clear();
11177  }
11178  public function isStarted()
11179  {
11180  return $this->started;
11181  }
11182  public function registerBag(SessionBagInterface $bag)
11183  {
11184  $this->bags[$bag->getStorageKey()] = $bag;
11185  }
11186  public function getBag($name)
11187  {
11188  return array_get($this->bags, $name, function () {
11189  throw new InvalidArgumentException('Bag not registered.');
11190  });
11191  }
11192  public function getMetadataBag()
11193  {
11194  return $this->metaBag;
11195  }
11196  public function getBagData($name)
11197  {
11198  return array_get($this->bagData, $name, array());
11199  }
11200  public function token()
11201  {
11202  return $this->get('_token');
11203  }
11204  public function getToken()
11205  {
11206  return $this->token();
11207  }
11208  public function regenerateToken()
11209  {
11210  $this->put('_token', str_random(40));
11211  }
11212  public function previousUrl()
11213  {
11214  return $this->get('_previous.url');
11215  }
11216  public function setPreviousUrl($url)
11217  {
11218  return $this->put('_previous.url', $url);
11219  }
11220  public function setExists($value)
11221  {
11222  if ($this->handler instanceof ExistenceAwareInterface) {
11223  $this->handler->setExists($value);
11224  }
11225  }
11226  public function getHandler()
11227  {
11228  return $this->handler;
11229  }
11230  public function handlerNeedsRequest()
11231  {
11232  return $this->handler instanceof CookieSessionHandler;
11233  }
11234  public function setRequestOnHandler(Request $request)
11235  {
11236  if ($this->handlerNeedsRequest()) {
11237  $this->handler->setRequest($request);
11238  }
11239  }
11240 }
11241 namespace Illuminate\Session;
11242 
11246 {
11247  protected function callCustomCreator($driver)
11248  {
11249  return $this->buildSession(parent::callCustomCreator($driver));
11250  }
11251  protected function createArrayDriver()
11252  {
11253  return $this->buildSession(new NullSessionHandler());
11254  }
11255  protected function createCookieDriver()
11256  {
11257  $lifetime = $this->app['config']['session.lifetime'];
11258  return $this->buildSession(new CookieSessionHandler($this->app['cookie'], $lifetime));
11259  }
11260  protected function createFileDriver()
11261  {
11262  return $this->createNativeDriver();
11263  }
11264  protected function createNativeDriver()
11265  {
11266  $path = $this->app['config']['session.files'];
11267  return $this->buildSession(new FileSessionHandler($this->app['files'], $path));
11268  }
11269  protected function createDatabaseDriver()
11270  {
11271  $connection = $this->getDatabaseConnection();
11272  $table = $this->app['config']['session.table'];
11273  return $this->buildSession(new DatabaseSessionHandler($connection, $table));
11274  }
11275  protected function getDatabaseConnection()
11276  {
11277  $connection = $this->app['config']['session.connection'];
11278  return $this->app['db']->connection($connection);
11279  }
11280  protected function createApcDriver()
11281  {
11282  return $this->createCacheBased('apc');
11283  }
11284  protected function createMemcachedDriver()
11285  {
11286  return $this->createCacheBased('memcached');
11287  }
11288  protected function createWincacheDriver()
11289  {
11290  return $this->createCacheBased('wincache');
11291  }
11292  protected function createRedisDriver()
11293  {
11294  $handler = $this->createCacheHandler('redis');
11295  $handler->getCache()->getStore()->setConnection($this->app['config']['session.connection']);
11296  return $this->buildSession($handler);
11297  }
11298  protected function createCacheBased($driver)
11299  {
11300  return $this->buildSession($this->createCacheHandler($driver));
11301  }
11302  protected function createCacheHandler($driver)
11303  {
11304  $minutes = $this->app['config']['session.lifetime'];
11305  return new CacheBasedSessionHandler($this->app['cache']->driver($driver), $minutes);
11306  }
11307  protected function buildSession($handler)
11308  {
11309  if ($this->app['config']['session.encrypt']) {
11310  return new EncryptedStore($this->app['config']['session.cookie'], $handler, $this->app['encrypter']);
11311  } else {
11312  return new Store($this->app['config']['session.cookie'], $handler);
11313  }
11314  }
11315  public function getSessionConfig()
11316  {
11317  return $this->app['config']['session'];
11318  }
11319  public function getDefaultDriver()
11320  {
11321  return $this->app['config']['session.driver'];
11322  }
11323  public function setDefaultDriver($name)
11324  {
11325  $this->app['config']['session.driver'] = $name;
11326  }
11327 }
11328 namespace Illuminate\Support;
11329 
11330 use Closure;
11331 use InvalidArgumentException;
11332 abstract class Manager
11333 {
11334  protected $app;
11335  protected $customCreators = array();
11336  protected $drivers = array();
11337  public function __construct($app)
11338  {
11339  $this->app = $app;
11340  }
11341  public abstract function getDefaultDriver();
11342  public function driver($driver = null)
11343  {
11344  $driver = $driver ?: $this->getDefaultDriver();
11345  if (!isset($this->drivers[$driver])) {
11346  $this->drivers[$driver] = $this->createDriver($driver);
11347  }
11348  return $this->drivers[$driver];
11349  }
11350  protected function createDriver($driver)
11351  {
11352  $method = 'create' . ucfirst($driver) . 'Driver';
11353  if (isset($this->customCreators[$driver])) {
11354  return $this->callCustomCreator($driver);
11355  } elseif (method_exists($this, $method)) {
11356  return $this->{$method}();
11357  }
11358  throw new InvalidArgumentException("Driver [{$driver}] not supported.");
11359  }
11360  protected function callCustomCreator($driver)
11361  {
11362  return $this->customCreators[$driver]($this->app);
11363  }
11364  public function extend($driver, Closure $callback)
11365  {
11366  $this->customCreators[$driver] = $callback;
11367  return $this;
11368  }
11369  public function getDrivers()
11370  {
11371  return $this->drivers;
11372  }
11373  public function __call($method, $parameters)
11374  {
11375  return call_user_func_array(array($this->driver(), $method), $parameters);
11376  }
11377 }
11378 namespace Illuminate\Support;
11379 
11380 use Closure;
11381 use Countable;
11382 use ArrayAccess;
11383 use ArrayIterator;
11384 use CachingIterator;
11385 use JsonSerializable;
11386 use IteratorAggregate;
11389 class Collection implements ArrayAccess, Arrayable, Countable, IteratorAggregate, Jsonable, JsonSerializable
11390 {
11391  protected $items = array();
11392  public function __construct($items = array())
11393  {
11394  $items = is_null($items) ? array() : $this->getArrayableItems($items);
11395  $this->items = (array) $items;
11396  }
11397  public static function make($items = null)
11398  {
11399  return new static($items);
11400  }
11401  public function all()
11402  {
11403  return $this->items;
11404  }
11405  public function collapse()
11406  {
11407  $results = array();
11408  foreach ($this->items as $values) {
11409  if ($values instanceof Collection) {
11410  $values = $values->all();
11411  }
11412  $results = array_merge($results, $values);
11413  }
11414  return new static($results);
11415  }
11416  public function contains($key, $value = null)
11417  {
11418  if (func_num_args() == 2) {
11419  return $this->contains(function ($k, $item) use($key, $value) {
11420  return data_get($item, $key) == $value;
11421  });
11422  }
11423  if ($this->useAsCallable($key)) {
11424  return !is_null($this->first($key));
11425  }
11426  return in_array($key, $this->items);
11427  }
11428  public function diff($items)
11429  {
11430  return new static(array_diff($this->items, $this->getArrayableItems($items)));
11431  }
11432  public function each(callable $callback)
11433  {
11434  array_map($callback, $this->items);
11435  return $this;
11436  }
11437  public function fetch($key)
11438  {
11439  return new static(array_fetch($this->items, $key));
11440  }
11441  public function filter(callable $callback)
11442  {
11443  return new static(array_filter($this->items, $callback));
11444  }
11445  public function where($key, $value, $strict = true)
11446  {
11447  return $this->filter(function ($item) use($key, $value, $strict) {
11448  return $strict ? data_get($item, $key) === $value : data_get($item, $key) == $value;
11449  });
11450  }
11451  public function whereLoose($key, $value)
11452  {
11453  return $this->where($key, $value, false);
11454  }
11455  public function first(callable $callback = null, $default = null)
11456  {
11457  if (is_null($callback)) {
11458  return count($this->items) > 0 ? reset($this->items) : null;
11459  }
11460  return array_first($this->items, $callback, $default);
11461  }
11462  public function flatten()
11463  {
11464  return new static(array_flatten($this->items));
11465  }
11466  public function flip()
11467  {
11468  return new static(array_flip($this->items));
11469  }
11470  public function forget($key)
11471  {
11472  $this->offsetUnset($key);
11473  }
11474  public function get($key, $default = null)
11475  {
11476  if ($this->offsetExists($key)) {
11477  return $this->items[$key];
11478  }
11479  return value($default);
11480  }
11481  public function groupBy($groupBy)
11482  {
11483  if (!$this->useAsCallable($groupBy)) {
11484  return $this->groupBy($this->valueRetriever($groupBy));
11485  }
11486  $results = array();
11487  foreach ($this->items as $key => $value) {
11488  $results[$groupBy($value, $key)][] = $value;
11489  }
11490  return new static($results);
11491  }
11492  public function keyBy($keyBy)
11493  {
11494  if (!$this->useAsCallable($keyBy)) {
11495  return $this->keyBy($this->valueRetriever($keyBy));
11496  }
11497  $results = array();
11498  foreach ($this->items as $item) {
11499  $results[$keyBy($item)] = $item;
11500  }
11501  return new static($results);
11502  }
11503  public function has($key)
11504  {
11505  return $this->offsetExists($key);
11506  }
11507  public function implode($value, $glue = null)
11508  {
11509  $first = $this->first();
11510  if (is_array($first) || is_object($first)) {
11511  return implode($glue, $this->lists($value));
11512  }
11513  return implode($value, $this->items);
11514  }
11515  public function intersect($items)
11516  {
11517  return new static(array_intersect($this->items, $this->getArrayableItems($items)));
11518  }
11519  public function isEmpty()
11520  {
11521  return empty($this->items);
11522  }
11523  protected function useAsCallable($value)
11524  {
11525  return !is_string($value) && is_callable($value);
11526  }
11527  public function keys()
11528  {
11529  return new static(array_keys($this->items));
11530  }
11531  public function last()
11532  {
11533  return count($this->items) > 0 ? end($this->items) : null;
11534  }
11535  public function lists($value, $key = null)
11536  {
11537  return array_pluck($this->items, $value, $key);
11538  }
11539  public function map(callable $callback)
11540  {
11541  return new static(array_map($callback, $this->items, array_keys($this->items)));
11542  }
11543  public function merge($items)
11544  {
11545  return new static(array_merge($this->items, $this->getArrayableItems($items)));
11546  }
11547  public function forPage($page, $perPage)
11548  {
11549  return new static(array_slice($this->items, ($page - 1) * $perPage, $perPage));
11550  }
11551  public function pop()
11552  {
11553  return array_pop($this->items);
11554  }
11555  public function prepend($value)
11556  {
11557  array_unshift($this->items, $value);
11558  }
11559  public function push($value)
11560  {
11561  $this->offsetSet(null, $value);
11562  }
11563  public function pull($key, $default = null)
11564  {
11565  return array_pull($this->items, $key, $default);
11566  }
11567  public function put($key, $value)
11568  {
11569  $this->offsetSet($key, $value);
11570  }
11571  public function random($amount = 1)
11572  {
11573  if ($this->isEmpty()) {
11574  return;
11575  }
11576  $keys = array_rand($this->items, $amount);
11577  return is_array($keys) ? array_intersect_key($this->items, array_flip($keys)) : $this->items[$keys];
11578  }
11579  public function reduce(callable $callback, $initial = null)
11580  {
11581  return array_reduce($this->items, $callback, $initial);
11582  }
11583  public function reject($callback)
11584  {
11585  if ($this->useAsCallable($callback)) {
11586  return $this->filter(function ($item) use($callback) {
11587  return !$callback($item);
11588  });
11589  }
11590  return $this->filter(function ($item) use($callback) {
11591  return $item != $callback;
11592  });
11593  }
11594  public function reverse()
11595  {
11596  return new static(array_reverse($this->items));
11597  }
11598  public function search($value, $strict = false)
11599  {
11600  return array_search($value, $this->items, $strict);
11601  }
11602  public function shift()
11603  {
11604  return array_shift($this->items);
11605  }
11606  public function shuffle()
11607  {
11608  shuffle($this->items);
11609  return $this;
11610  }
11611  public function slice($offset, $length = null, $preserveKeys = false)
11612  {
11613  return new static(array_slice($this->items, $offset, $length, $preserveKeys));
11614  }
11615  public function chunk($size, $preserveKeys = false)
11616  {
11617  $chunks = array();
11618  foreach (array_chunk($this->items, $size, $preserveKeys) as $chunk) {
11619  $chunks[] = new static($chunk);
11620  }
11621  return new static($chunks);
11622  }
11623  public function sort(callable $callback)
11624  {
11625  uasort($this->items, $callback);
11626  return $this;
11627  }
11628  public function sortBy($callback, $options = SORT_REGULAR, $descending = false)
11629  {
11630  $results = array();
11631  if (!$this->useAsCallable($callback)) {
11632  $callback = $this->valueRetriever($callback);
11633  }
11634  foreach ($this->items as $key => $value) {
11635  $results[$key] = $callback($value, $key);
11636  }
11637  $descending ? arsort($results, $options) : asort($results, $options);
11638  foreach (array_keys($results) as $key) {
11639  $results[$key] = $this->items[$key];
11640  }
11641  $this->items = $results;
11642  return $this;
11643  }
11644  public function sortByDesc($callback, $options = SORT_REGULAR)
11645  {
11646  return $this->sortBy($callback, $options, true);
11647  }
11648  public function splice($offset, $length = 0, $replacement = array())
11649  {
11650  return new static(array_splice($this->items, $offset, $length, $replacement));
11651  }
11652  public function sum($callback = null)
11653  {
11654  if (is_null($callback)) {
11655  return array_sum($this->items);
11656  }
11657  if (!$this->useAsCallable($callback)) {
11658  $callback = $this->valueRetriever($callback);
11659  }
11660  return $this->reduce(function ($result, $item) use($callback) {
11661  return $result += $callback($item);
11662  }, 0);
11663  }
11664  public function take($limit = null)
11665  {
11666  if ($limit < 0) {
11667  return $this->slice($limit, abs($limit));
11668  }
11669  return $this->slice(0, $limit);
11670  }
11671  public function transform(callable $callback)
11672  {
11673  $this->items = array_map($callback, $this->items);
11674  return $this;
11675  }
11676  public function unique()
11677  {
11678  return new static(array_unique($this->items));
11679  }
11680  public function values()
11681  {
11682  return new static(array_values($this->items));
11683  }
11684  protected function valueRetriever($value)
11685  {
11686  return function ($item) use($value) {
11687  return data_get($item, $value);
11688  };
11689  }
11690  public function toArray()
11691  {
11692  return array_map(function ($value) {
11693  return $value instanceof Arrayable ? $value->toArray() : $value;
11694  }, $this->items);
11695  }
11696  public function jsonSerialize()
11697  {
11698  return $this->toArray();
11699  }
11700  public function toJson($options = 0)
11701  {
11702  return json_encode($this->toArray(), $options);
11703  }
11704  public function getIterator()
11705  {
11706  return new ArrayIterator($this->items);
11707  }
11708  public function getCachingIterator($flags = CachingIterator::CALL_TOSTRING)
11709  {
11710  return new CachingIterator($this->getIterator(), $flags);
11711  }
11712  public function count()
11713  {
11714  return count($this->items);
11715  }
11716  public function offsetExists($key)
11717  {
11718  return array_key_exists($key, $this->items);
11719  }
11720  public function offsetGet($key)
11721  {
11722  return $this->items[$key];
11723  }
11724  public function offsetSet($key, $value)
11725  {
11726  if (is_null($key)) {
11727  $this->items[] = $value;
11728  } else {
11729  $this->items[$key] = $value;
11730  }
11731  }
11732  public function offsetUnset($key)
11733  {
11734  unset($this->items[$key]);
11735  }
11736  public function __toString()
11737  {
11738  return $this->toJson();
11739  }
11740  protected function getArrayableItems($items)
11741  {
11742  if ($items instanceof Collection) {
11743  $items = $items->all();
11744  } elseif ($items instanceof Arrayable) {
11745  $items = $items->toArray();
11746  }
11747  return $items;
11748  }
11749 }
11750 namespace Illuminate\Cookie;
11751 
11754 class CookieJar implements JarContract
11755 {
11756  protected $path = '/';
11757  protected $domain = null;
11758  protected $queued = array();
11759  public function make($name, $value, $minutes = 0, $path = null, $domain = null, $secure = false, $httpOnly = true)
11760  {
11761  list($path, $domain) = $this->getPathAndDomain($path, $domain);
11762  $time = $minutes == 0 ? 0 : time() + $minutes * 60;
11763  return new Cookie($name, $value, $time, $path, $domain, $secure, $httpOnly);
11764  }
11765  public function forever($name, $value, $path = null, $domain = null, $secure = false, $httpOnly = true)
11766  {
11767  return $this->make($name, $value, 2628000, $path, $domain, $secure, $httpOnly);
11768  }
11769  public function forget($name, $path = null, $domain = null)
11770  {
11771  return $this->make($name, null, -2628000, $path, $domain);
11772  }
11773  public function hasQueued($key)
11774  {
11775  return !is_null($this->queued($key));
11776  }
11777  public function queued($key, $default = null)
11778  {
11779  return array_get($this->queued, $key, $default);
11780  }
11781  public function queue()
11782  {
11783  if (head(func_get_args()) instanceof Cookie) {
11784  $cookie = head(func_get_args());
11785  } else {
11786  $cookie = call_user_func_array(array($this, 'make'), func_get_args());
11787  }
11788  $this->queued[$cookie->getName()] = $cookie;
11789  }
11790  public function unqueue($name)
11791  {
11792  unset($this->queued[$name]);
11793  }
11794  protected function getPathAndDomain($path, $domain)
11795  {
11796  return array($path ?: $this->path, $domain ?: $this->domain);
11797  }
11798  public function setDefaultPathAndDomain($path, $domain)
11799  {
11800  list($this->path, $this->domain) = array($path, $domain);
11801  return $this;
11802  }
11803  public function getQueuedCookies()
11804  {
11805  return $this->queued;
11806  }
11807 }
11809 
11810 use Closure;
11817 class EncryptCookies implements Middleware
11818 {
11819  protected $encrypter;
11820  public function __construct(EncrypterContract $encrypter)
11821  {
11822  $this->encrypter = $encrypter;
11823  }
11824  public function handle($request, Closure $next)
11825  {
11826  return $this->encrypt($next($this->decrypt($request)));
11827  }
11828  protected function decrypt(Request $request)
11829  {
11830  foreach ($request->cookies as $key => $c) {
11831  try {
11832  $request->cookies->set($key, $this->decryptCookie($c));
11833  } catch (DecryptException $e) {
11834  $request->cookies->set($key, null);
11835  }
11836  }
11837  return $request;
11838  }
11839  protected function decryptCookie($cookie)
11840  {
11841  return is_array($cookie) ? $this->decryptArray($cookie) : $this->encrypter->decrypt($cookie);
11842  }
11843  protected function decryptArray(array $cookie)
11844  {
11845  $decrypted = array();
11846  foreach ($cookie as $key => $value) {
11847  $decrypted[$key] = $this->encrypter->decrypt($value);
11848  }
11849  return $decrypted;
11850  }
11851  protected function encrypt(Response $response)
11852  {
11853  foreach ($response->headers->getCookies() as $key => $cookie) {
11854  $response->headers->setCookie($this->duplicate($cookie, $this->encrypter->encrypt($cookie->getValue())));
11855  }
11856  return $response;
11857  }
11858  protected function duplicate(Cookie $c, $value)
11859  {
11860  return new Cookie($c->getName(), $value, $c->getExpiresTime(), $c->getPath(), $c->getDomain(), $c->isSecure(), $c->isHttpOnly());
11861  }
11862 }
11864 
11865 use Closure;
11869 {
11870  protected $cookies;
11871  public function __construct(CookieJar $cookies)
11872  {
11873  $this->cookies = $cookies;
11874  }
11875  public function handle($request, Closure $next)
11876  {
11877  $response = $next($request);
11878  foreach ($this->cookies->getQueuedCookies() as $cookie) {
11879  $response->headers->setCookie($cookie);
11880  }
11881  return $response;
11882  }
11883 }
11884 namespace Illuminate\Encryption;
11885 
11886 use Exception;
11890 use Illuminate\Contracts\Encryption\Encrypter as EncrypterContract;
11891 class Encrypter implements EncrypterContract
11892 {
11893  protected $key;
11894  protected $cipher = MCRYPT_RIJNDAEL_128;
11895  protected $mode = MCRYPT_MODE_CBC;
11896  protected $block = 16;
11897  public function __construct($key)
11898  {
11899  $this->key = (string) $key;
11900  }
11901  public function encrypt($value)
11902  {
11903  $iv = mcrypt_create_iv($this->getIvSize(), $this->getRandomizer());
11904  $value = base64_encode($this->padAndMcrypt($value, $iv));
11905  $mac = $this->hash($iv = base64_encode($iv), $value);
11906  return base64_encode(json_encode(compact('iv', 'value', 'mac')));
11907  }
11908  protected function padAndMcrypt($value, $iv)
11909  {
11910  $value = $this->addPadding(serialize($value));
11911  return mcrypt_encrypt($this->cipher, $this->key, $value, $this->mode, $iv);
11912  }
11913  public function decrypt($payload)
11914  {
11915  $payload = $this->getJsonPayload($payload);
11916  $value = base64_decode($payload['value']);
11917  $iv = base64_decode($payload['iv']);
11918  return unserialize($this->stripPadding($this->mcryptDecrypt($value, $iv)));
11919  }
11920  protected function mcryptDecrypt($value, $iv)
11921  {
11922  try {
11923  return mcrypt_decrypt($this->cipher, $this->key, $value, $this->mode, $iv);
11924  } catch (Exception $e) {
11925  throw new DecryptException($e->getMessage());
11926  }
11927  }
11928  protected function getJsonPayload($payload)
11929  {
11930  $payload = json_decode(base64_decode($payload), true);
11931  if (!$payload || $this->invalidPayload($payload)) {
11932  throw new DecryptException('Invalid data.');
11933  }
11934  if (!$this->validMac($payload)) {
11935  throw new DecryptException('MAC is invalid.');
11936  }
11937  return $payload;
11938  }
11939  protected function validMac(array $payload)
11940  {
11941  $bytes = (new SecureRandom())->nextBytes(16);
11942  $calcMac = hash_hmac('sha256', $this->hash($payload['iv'], $payload['value']), $bytes, true);
11943  return StringUtils::equals(hash_hmac('sha256', $payload['mac'], $bytes, true), $calcMac);
11944  }
11945  protected function hash($iv, $value)
11946  {
11947  return hash_hmac('sha256', $iv . $value, $this->key);
11948  }
11949  protected function addPadding($value)
11950  {
11951  $pad = $this->block - strlen($value) % $this->block;
11952  return $value . str_repeat(chr($pad), $pad);
11953  }
11954  protected function stripPadding($value)
11955  {
11956  $pad = ord($value[($len = strlen($value)) - 1]);
11957  return $this->paddingIsValid($pad, $value) ? substr($value, 0, $len - $pad) : $value;
11958  }
11959  protected function paddingIsValid($pad, $value)
11960  {
11961  $beforePad = strlen($value) - $pad;
11962  return substr($value, $beforePad) == str_repeat(substr($value, -1), $pad);
11963  }
11964  protected function invalidPayload($data)
11965  {
11966  return !is_array($data) || !isset($data['iv']) || !isset($data['value']) || !isset($data['mac']);
11967  }
11968  protected function getIvSize()
11969  {
11970  return mcrypt_get_iv_size($this->cipher, $this->mode);
11971  }
11972  protected function getRandomizer()
11973  {
11974  if (defined('MCRYPT_DEV_URANDOM')) {
11975  return MCRYPT_DEV_URANDOM;
11976  }
11977  if (defined('MCRYPT_DEV_RANDOM')) {
11978  return MCRYPT_DEV_RANDOM;
11979  }
11980  mt_srand();
11981  return MCRYPT_RAND;
11982  }
11983  public function setKey($key)
11984  {
11985  $this->key = (string) $key;
11986  }
11987  public function setCipher($cipher)
11988  {
11989  $this->cipher = $cipher;
11990  $this->updateBlockSize();
11991  }
11992  public function setMode($mode)
11993  {
11994  $this->mode = $mode;
11995  $this->updateBlockSize();
11996  }
11997  protected function updateBlockSize()
11998  {
11999  $this->block = mcrypt_get_iv_size($this->cipher, $this->mode);
12000  }
12001 }
12002 namespace Illuminate\Support\Facades;
12003 
12004 class Log extends Facade
12005 {
12006  protected static function getFacadeAccessor()
12007  {
12008  return 'log';
12009  }
12010 }
12011 namespace Illuminate\Log;
12012 
12013 use Closure;
12014 use RuntimeException;
12015 use InvalidArgumentException;
12026 use Illuminate\Contracts\Logging\Log as LogContract;
12027 class Writer implements LogContract, PsrLoggerInterface
12028 {
12029  protected $monolog;
12030  protected $dispatcher;
12031  protected $levels = array('debug' => MonologLogger::DEBUG, 'info' => MonologLogger::INFO, 'notice' => MonologLogger::NOTICE, 'warning' => MonologLogger::WARNING, 'error' => MonologLogger::ERROR, 'critical' => MonologLogger::CRITICAL, 'alert' => MonologLogger::ALERT, 'emergency' => MonologLogger::EMERGENCY);
12032  public function __construct(MonologLogger $monolog, Dispatcher $dispatcher = null)
12033  {
12034  $this->monolog = $monolog;
12035  if (isset($dispatcher)) {
12036  $this->dispatcher = $dispatcher;
12037  }
12038  }
12039  public function emergency($message, array $context = array())
12040  {
12041  return $this->writeLog(__FUNCTION__, $message, $context);
12042  }
12043  public function alert($message, array $context = array())
12044  {
12045  return $this->writeLog(__FUNCTION__, $message, $context);
12046  }
12047  public function critical($message, array $context = array())
12048  {
12049  return $this->writeLog(__FUNCTION__, $message, $context);
12050  }
12051  public function error($message, array $context = array())
12052  {
12053  return $this->writeLog(__FUNCTION__, $message, $context);
12054  }
12055  public function warning($message, array $context = array())
12056  {
12057  return $this->writeLog(__FUNCTION__, $message, $context);
12058  }
12059  public function notice($message, array $context = array())
12060  {
12061  return $this->writeLog(__FUNCTION__, $message, $context);
12062  }
12063  public function info($message, array $context = array())
12064  {
12065  return $this->writeLog(__FUNCTION__, $message, $context);
12066  }
12067  public function debug($message, array $context = array())
12068  {
12069  return $this->writeLog(__FUNCTION__, $message, $context);
12070  }
12071  public function log($level, $message, array $context = array())
12072  {
12073  return $this->writeLog($level, $message, $context);
12074  }
12075  public function write($level, $message, array $context = array())
12076  {
12077  return $this->writeLog($level, $message, $context);
12078  }
12079  protected function writeLog($level, $message, $context)
12080  {
12081  $this->fireLogEvent($level, $message = $this->formatMessage($message), $context);
12082  $this->monolog->{$level}($message, $context);
12083  }
12084  public function useFiles($path, $level = 'debug')
12085  {
12086  $this->monolog->pushHandler($handler = new StreamHandler($path, $this->parseLevel($level)));
12087  $handler->setFormatter($this->getDefaultFormatter());
12088  }
12089  public function useDailyFiles($path, $days = 0, $level = 'debug')
12090  {
12091  $this->monolog->pushHandler($handler = new RotatingFileHandler($path, $days, $this->parseLevel($level)));
12092  $handler->setFormatter($this->getDefaultFormatter());
12093  }
12094  public function useSyslog($name = 'laravel', $level = 'debug')
12095  {
12096  return $this->monolog->pushHandler(new SyslogHandler($name, LOG_USER, $level));
12097  }
12098  public function useErrorLog($level = 'debug', $messageType = ErrorLogHandler::OPERATING_SYSTEM)
12099  {
12100  $this->monolog->pushHandler($handler = new ErrorLogHandler($messageType, $this->parseLevel($level)));
12101  $handler->setFormatter($this->getDefaultFormatter());
12102  }
12103  public function listen(Closure $callback)
12104  {
12105  if (!isset($this->dispatcher)) {
12106  throw new RuntimeException('Events dispatcher has not been set.');
12107  }
12108  $this->dispatcher->listen('illuminate.log', $callback);
12109  }
12110  protected function fireLogEvent($level, $message, array $context = array())
12111  {
12112  if (isset($this->dispatcher)) {
12113  $this->dispatcher->fire('illuminate.log', compact('level', 'message', 'context'));
12114  }
12115  }
12116  protected function formatMessage($message)
12117  {
12118  if (is_array($message)) {
12119  return var_export($message, true);
12120  } elseif ($message instanceof Jsonable) {
12121  return $message->toJson();
12122  } elseif ($message instanceof Arrayable) {
12123  return var_export($message->toArray(), true);
12124  }
12125  return $message;
12126  }
12127  protected function parseLevel($level)
12128  {
12129  if (isset($this->levels[$level])) {
12130  return $this->levels[$level];
12131  }
12132  throw new InvalidArgumentException('Invalid log level.');
12133  }
12134  public function getMonolog()
12135  {
12136  return $this->monolog;
12137  }
12138  protected function getDefaultFormatter()
12139  {
12140  return new LineFormatter(null, null, true, true);
12141  }
12142  public function getEventDispatcher()
12143  {
12144  return $this->dispatcher;
12145  }
12146  public function setEventDispatcher(Dispatcher $dispatcher)
12147  {
12148  $this->dispatcher = $dispatcher;
12149  }
12150 }
12152 
12153 use Closure;
12158 {
12159  protected $view;
12160  public function __construct(ViewFactory $view)
12161  {
12162  $this->view = $view;
12163  }
12164  public function handle($request, Closure $next)
12165  {
12166  if ($request->session()->has('errors')) {
12167  $this->view->share('errors', $request->session()->get('errors'));
12168  } else {
12169  $this->view->share('errors', new ViewErrorBag());
12170  }
12171  return $next($request);
12172  }
12173 }
12174 namespace Monolog;
12175 
12180 class Logger implements LoggerInterface
12181 {
12182  const DEBUG = 100;
12183  const INFO = 200;
12184  const NOTICE = 250;
12185  const WARNING = 300;
12186  const ERROR = 400;
12187  const CRITICAL = 500;
12188  const ALERT = 550;
12189  const EMERGENCY = 600;
12190  const API = 1;
12191  protected static $levels = array(100 => 'DEBUG', 200 => 'INFO', 250 => 'NOTICE', 300 => 'WARNING', 400 => 'ERROR', 500 => 'CRITICAL', 550 => 'ALERT', 600 => 'EMERGENCY');
12192  protected static $timezone;
12193  protected $name;
12194  protected $handlers;
12195  protected $processors;
12196  public function __construct($name, array $handlers = array(), array $processors = array())
12197  {
12198  $this->name = $name;
12199  $this->handlers = $handlers;
12200  $this->processors = $processors;
12201  }
12202  public function getName()
12203  {
12204  return $this->name;
12205  }
12206  public function pushHandler(HandlerInterface $handler)
12207  {
12208  array_unshift($this->handlers, $handler);
12209  }
12210  public function popHandler()
12211  {
12212  if (!$this->handlers) {
12213  throw new \LogicException('You tried to pop from an empty handler stack.');
12214  }
12215  return array_shift($this->handlers);
12216  }
12217  public function getHandlers()
12218  {
12219  return $this->handlers;
12220  }
12221  public function pushProcessor($callback)
12222  {
12223  if (!is_callable($callback)) {
12224  throw new \InvalidArgumentException('Processors must be valid callables (callback or object with an __invoke method), ' . var_export($callback, true) . ' given');
12225  }
12226  array_unshift($this->processors, $callback);
12227  }
12228  public function popProcessor()
12229  {
12230  if (!$this->processors) {
12231  throw new \LogicException('You tried to pop from an empty processor stack.');
12232  }
12233  return array_shift($this->processors);
12234  }
12235  public function getProcessors()
12236  {
12237  return $this->processors;
12238  }
12239  public function addRecord($level, $message, array $context = array())
12240  {
12241  if (!$this->handlers) {
12242  $this->pushHandler(new StreamHandler('php://stderr', static::DEBUG));
12243  }
12244  $levelName = static::getLevelName($level);
12245  $handlerKey = null;
12246  foreach ($this->handlers as $key => $handler) {
12247  if ($handler->isHandling(array('level' => $level))) {
12248  $handlerKey = $key;
12249  break;
12250  }
12251  }
12252  if (null === $handlerKey) {
12253  return false;
12254  }
12255  if (!static::$timezone) {
12256  static::$timezone = new \DateTimeZone(date_default_timezone_get() ?: 'UTC');
12257  }
12258  $record = array('message' => (string) $message, 'context' => $context, 'level' => $level, 'level_name' => $levelName, 'channel' => $this->name, 'datetime' => \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), static::$timezone)->setTimezone(static::$timezone), 'extra' => array());
12259  foreach ($this->processors as $processor) {
12260  $record = call_user_func($processor, $record);
12261  }
12262  while (isset($this->handlers[$handlerKey]) && false === $this->handlers[$handlerKey]->handle($record)) {
12263  $handlerKey++;
12264  }
12265  return true;
12266  }
12267  public function addDebug($message, array $context = array())
12268  {
12269  return $this->addRecord(static::DEBUG, $message, $context);
12270  }
12271  public function addInfo($message, array $context = array())
12272  {
12273  return $this->addRecord(static::INFO, $message, $context);
12274  }
12275  public function addNotice($message, array $context = array())
12276  {
12277  return $this->addRecord(static::NOTICE, $message, $context);
12278  }
12279  public function addWarning($message, array $context = array())
12280  {
12281  return $this->addRecord(static::WARNING, $message, $context);
12282  }
12283  public function addError($message, array $context = array())
12284  {
12285  return $this->addRecord(static::ERROR, $message, $context);
12286  }
12287  public function addCritical($message, array $context = array())
12288  {
12289  return $this->addRecord(static::CRITICAL, $message, $context);
12290  }
12291  public function addAlert($message, array $context = array())
12292  {
12293  return $this->addRecord(static::ALERT, $message, $context);
12294  }
12295  public function addEmergency($message, array $context = array())
12296  {
12297  return $this->addRecord(static::EMERGENCY, $message, $context);
12298  }
12299  public static function getLevels()
12300  {
12301  return array_flip(static::$levels);
12302  }
12303  public static function getLevelName($level)
12304  {
12305  if (!isset(static::$levels[$level])) {
12306  throw new InvalidArgumentException('Level "' . $level . '" is not defined, use one of: ' . implode(', ', array_keys(static::$levels)));
12307  }
12308  return static::$levels[$level];
12309  }
12310  public static function toMonologLevel($level)
12311  {
12312  if (is_string($level) && defined(__CLASS__ . '::' . strtoupper($level))) {
12313  return constant(__CLASS__ . '::' . strtoupper($level));
12314  }
12315  return $level;
12316  }
12317  public function isHandling($level)
12318  {
12319  $record = array('level' => $level);
12320  foreach ($this->handlers as $handler) {
12321  if ($handler->isHandling($record)) {
12322  return true;
12323  }
12324  }
12325  return false;
12326  }
12327  public function log($level, $message, array $context = array())
12328  {
12329  if (is_string($level) && defined(__CLASS__ . '::' . strtoupper($level))) {
12330  $level = constant(__CLASS__ . '::' . strtoupper($level));
12331  }
12332  return $this->addRecord($level, $message, $context);
12333  }
12334  public function debug($message, array $context = array())
12335  {
12336  return $this->addRecord(static::DEBUG, $message, $context);
12337  }
12338  public function info($message, array $context = array())
12339  {
12340  return $this->addRecord(static::INFO, $message, $context);
12341  }
12342  public function notice($message, array $context = array())
12343  {
12344  return $this->addRecord(static::NOTICE, $message, $context);
12345  }
12346  public function warn($message, array $context = array())
12347  {
12348  return $this->addRecord(static::WARNING, $message, $context);
12349  }
12350  public function warning($message, array $context = array())
12351  {
12352  return $this->addRecord(static::WARNING, $message, $context);
12353  }
12354  public function err($message, array $context = array())
12355  {
12356  return $this->addRecord(static::ERROR, $message, $context);
12357  }
12358  public function error($message, array $context = array())
12359  {
12360  return $this->addRecord(static::ERROR, $message, $context);
12361  }
12362  public function crit($message, array $context = array())
12363  {
12364  return $this->addRecord(static::CRITICAL, $message, $context);
12365  }
12366  public function critical($message, array $context = array())
12367  {
12368  return $this->addRecord(static::CRITICAL, $message, $context);
12369  }
12370  public function alert($message, array $context = array())
12371  {
12372  return $this->addRecord(static::ALERT, $message, $context);
12373  }
12374  public function emerg($message, array $context = array())
12375  {
12376  return $this->addRecord(static::EMERGENCY, $message, $context);
12377  }
12378  public function emergency($message, array $context = array())
12379  {
12380  return $this->addRecord(static::EMERGENCY, $message, $context);
12381  }
12382 }
12383 namespace Psr\Log;
12384 
12386 {
12387  public function emergency($message, array $context = array());
12388  public function alert($message, array $context = array());
12389  public function critical($message, array $context = array());
12390  public function error($message, array $context = array());
12391  public function warning($message, array $context = array());
12392  public function notice($message, array $context = array());
12393  public function info($message, array $context = array());
12394  public function debug($message, array $context = array());
12395  public function log($level, $message, array $context = array());
12396 }
12398 
12399 use Monolog\Logger;
12402 abstract class AbstractHandler implements HandlerInterface
12403 {
12404  protected $level = Logger::DEBUG;
12405  protected $bubble = true;
12406  protected $formatter;
12407  protected $processors = array();
12408  public function __construct($level = Logger::DEBUG, $bubble = true)
12409  {
12410  $this->setLevel($level);
12411  $this->bubble = $bubble;
12412  }
12413  public function isHandling(array $record)
12414  {
12415  return $record['level'] >= $this->level;
12416  }
12417  public function handleBatch(array $records)
12418  {
12419  foreach ($records as $record) {
12420  $this->handle($record);
12421  }
12422  }
12423  public function close()
12424  {
12425  }
12426  public function pushProcessor($callback)
12427  {
12428  if (!is_callable($callback)) {
12429  throw new \InvalidArgumentException('Processors must be valid callables (callback or object with an __invoke method), ' . var_export($callback, true) . ' given');
12430  }
12431  array_unshift($this->processors, $callback);
12432  return $this;
12433  }
12434  public function popProcessor()
12435  {
12436  if (!$this->processors) {
12437  throw new \LogicException('You tried to pop from an empty processor stack.');
12438  }
12439  return array_shift($this->processors);
12440  }
12441  public function setFormatter(FormatterInterface $formatter)
12442  {
12443  $this->formatter = $formatter;
12444  return $this;
12445  }
12446  public function getFormatter()
12447  {
12448  if (!$this->formatter) {
12449  $this->formatter = $this->getDefaultFormatter();
12450  }
12451  return $this->formatter;
12452  }
12453  public function setLevel($level)
12454  {
12455  $this->level = Logger::toMonologLevel($level);
12456  return $this;
12457  }
12458  public function getLevel()
12459  {
12460  return $this->level;
12461  }
12462  public function setBubble($bubble)
12463  {
12464  $this->bubble = $bubble;
12465  return $this;
12466  }
12467  public function getBubble()
12468  {
12469  return $this->bubble;
12470  }
12471  public function __destruct()
12472  {
12473  try {
12474  $this->close();
12475  } catch (\Exception $e) {
12476  }
12477  }
12478  protected function getDefaultFormatter()
12479  {
12480  return new LineFormatter();
12481  }
12482 }
12483 namespace Monolog\Handler;
12484 
12486 {
12487  public function handle(array $record)
12488  {
12489  if (!$this->isHandling($record)) {
12490  return false;
12491  }
12492  $record = $this->processRecord($record);
12493  $record['formatted'] = $this->getFormatter()->format($record);
12494  $this->write($record);
12495  return false === $this->bubble;
12496  }
12497  protected abstract function write(array $record);
12498  protected function processRecord(array $record)
12499  {
12500  if ($this->processors) {
12501  foreach ($this->processors as $processor) {
12502  $record = call_user_func($processor, $record);
12503  }
12504  }
12505  return $record;
12506  }
12507 }
12508 namespace Monolog\Handler;
12509 
12510 use Monolog\Logger;
12512 {
12513  protected $stream;
12514  protected $url;
12515  private $errorMessage;
12516  protected $filePermission;
12517  protected $useLocking;
12518  public function __construct($stream, $level = Logger::DEBUG, $bubble = true, $filePermission = null, $useLocking = false)
12519  {
12520  parent::__construct($level, $bubble);
12521  if (is_resource($stream)) {
12522  $this->stream = $stream;
12523  } elseif (is_string($stream)) {
12524  $this->url = $stream;
12525  } else {
12526  throw new \InvalidArgumentException('A stream must either be a resource or a string.');
12527  }
12528  $this->filePermission = $filePermission;
12529  $this->useLocking = $useLocking;
12530  }
12531  public function close()
12532  {
12533  if (is_resource($this->stream)) {
12534  fclose($this->stream);
12535  }
12536  $this->stream = null;
12537  }
12538  protected function write(array $record)
12539  {
12540  if (!is_resource($this->stream)) {
12541  if (!$this->url) {
12542  throw new \LogicException('Missing stream url, the stream can not be opened. This may be caused by a premature call to close().');
12543  }
12544  $this->errorMessage = null;
12545  set_error_handler(array($this, 'customErrorHandler'));
12546  $this->stream = fopen($this->url, 'a');
12547  if ($this->filePermission !== null) {
12548  @chmod($this->url, $this->filePermission);
12549  }
12550  restore_error_handler();
12551  if (!is_resource($this->stream)) {
12552  $this->stream = null;
12553  throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: ' . $this->errorMessage, $this->url));
12554  }
12555  }
12556  if ($this->useLocking) {
12557  flock($this->stream, LOCK_EX);
12558  }
12559  fwrite($this->stream, (string) $record['formatted']);
12560  if ($this->useLocking) {
12561  flock($this->stream, LOCK_UN);
12562  }
12563  }
12564  private function customErrorHandler($code, $msg)
12565  {
12566  $this->errorMessage = preg_replace('{^fopen\\(.*?\\): }', '', $msg);
12567  }
12568 }
12569 namespace Monolog\Handler;
12570 
12571 use Monolog\Logger;
12573 {
12574  protected $filename;
12575  protected $maxFiles;
12576  protected $mustRotate;
12577  protected $nextRotation;
12578  protected $filenameFormat;
12579  protected $dateFormat;
12580  public function __construct($filename, $maxFiles = 0, $level = Logger::DEBUG, $bubble = true, $filePermission = null, $useLocking = false)
12581  {
12582  $this->filename = $filename;
12583  $this->maxFiles = (int) $maxFiles;
12584  $this->nextRotation = new \DateTime('tomorrow');
12585  $this->filenameFormat = '{filename}-{date}';
12586  $this->dateFormat = 'Y-m-d';
12587  parent::__construct($this->getTimedFilename(), $level, $bubble, $filePermission, $useLocking);
12588  }
12589  public function close()
12590  {
12591  parent::close();
12592  if (true === $this->mustRotate) {
12593  $this->rotate();
12594  }
12595  }
12596  public function setFilenameFormat($filenameFormat, $dateFormat)
12597  {
12598  $this->filenameFormat = $filenameFormat;
12599  $this->dateFormat = $dateFormat;
12600  $this->url = $this->getTimedFilename();
12601  $this->close();
12602  }
12603  protected function write(array $record)
12604  {
12605  if (null === $this->mustRotate) {
12606  $this->mustRotate = !file_exists($this->url);
12607  }
12608  if ($this->nextRotation < $record['datetime']) {
12609  $this->mustRotate = true;
12610  $this->close();
12611  }
12612  parent::write($record);
12613  }
12614  protected function rotate()
12615  {
12616  $this->url = $this->getTimedFilename();
12617  $this->nextRotation = new \DateTime('tomorrow');
12618  if (0 === $this->maxFiles) {
12619  return;
12620  }
12621  $logFiles = glob($this->getGlobPattern());
12622  if ($this->maxFiles >= count($logFiles)) {
12623  return;
12624  }
12625  usort($logFiles, function ($a, $b) {
12626  return strcmp($b, $a);
12627  });
12628  foreach (array_slice($logFiles, $this->maxFiles) as $file) {
12629  if (is_writable($file)) {
12630  unlink($file);
12631  }
12632  }
12633  }
12634  protected function getTimedFilename()
12635  {
12636  $fileInfo = pathinfo($this->filename);
12637  $timedFilename = str_replace(array('{filename}', '{date}'), array($fileInfo['filename'], date($this->dateFormat)), $fileInfo['dirname'] . '/' . $this->filenameFormat);
12638  if (!empty($fileInfo['extension'])) {
12639  $timedFilename .= '.' . $fileInfo['extension'];
12640  }
12641  return $timedFilename;
12642  }
12643  protected function getGlobPattern()
12644  {
12645  $fileInfo = pathinfo($this->filename);
12646  $glob = str_replace(array('{filename}', '{date}'), array($fileInfo['filename'], '*'), $fileInfo['dirname'] . '/' . $this->filenameFormat);
12647  if (!empty($fileInfo['extension'])) {
12648  $glob .= '.' . $fileInfo['extension'];
12649  }
12650  return $glob;
12651  }
12652 }
12653 namespace Monolog\Handler;
12654 
12657 {
12658  public function isHandling(array $record);
12659  public function handle(array $record);
12660  public function handleBatch(array $records);
12661  public function pushProcessor($callback);
12662  public function popProcessor();
12663  public function setFormatter(FormatterInterface $formatter);
12664  public function getFormatter();
12665 }
12667 
12669 {
12670  public function format(array $record);
12671  public function formatBatch(array $records);
12672 }
12673 namespace Monolog\Formatter;
12674 
12675 use Exception;
12677 {
12678  const SIMPLE_DATE = 'Y-m-d H:i:s';
12679  protected $dateFormat;
12680  public function __construct($dateFormat = null)
12681  {
12682  $this->dateFormat = $dateFormat ?: static::SIMPLE_DATE;
12683  if (!function_exists('json_encode')) {
12684  throw new \RuntimeException('PHP\'s json extension is required to use Monolog\'s NormalizerFormatter');
12685  }
12686  }
12687  public function format(array $record)
12688  {
12689  return $this->normalize($record);
12690  }
12691  public function formatBatch(array $records)
12692  {
12693  foreach ($records as $key => $record) {
12694  $records[$key] = $this->format($record);
12695  }
12696  return $records;
12697  }
12698  protected function normalize($data)
12699  {
12700  if (null === $data || is_scalar($data)) {
12701  if (is_float($data)) {
12702  if (is_infinite($data)) {
12703  return ($data > 0 ? '' : '-') . 'INF';
12704  }
12705  if (is_nan($data)) {
12706  return 'NaN';
12707  }
12708  }
12709  return $data;
12710  }
12711  if (is_array($data) || $data instanceof \Traversable) {
12712  $normalized = array();
12713  $count = 1;
12714  foreach ($data as $key => $value) {
12715  if ($count++ >= 1000) {
12716  $normalized['...'] = 'Over 1000 items, aborting normalization';
12717  break;
12718  }
12719  $normalized[$key] = $this->normalize($value);
12720  }
12721  return $normalized;
12722  }
12723  if ($data instanceof \DateTime) {
12724  return $data->format($this->dateFormat);
12725  }
12726  if (is_object($data)) {
12727  if ($data instanceof Exception) {
12728  return $this->normalizeException($data);
12729  }
12730  return sprintf('[object] (%s: %s)', get_class($data), $this->toJson($data, true));
12731  }
12732  if (is_resource($data)) {
12733  return '[resource]';
12734  }
12735  return '[unknown(' . gettype($data) . ')]';
12736  }
12737  protected function normalizeException(Exception $e)
12738  {
12739  $data = array('class' => get_class($e), 'message' => $e->getMessage(), 'code' => $e->getCode(), 'file' => $e->getFile() . ':' . $e->getLine());
12740  $trace = $e->getTrace();
12741  foreach ($trace as $frame) {
12742  if (isset($frame['file'])) {
12743  $data['trace'][] = $frame['file'] . ':' . $frame['line'];
12744  } else {
12745  $data['trace'][] = $this->toJson($this->normalize($frame), true);
12746  }
12747  }
12748  if ($previous = $e->getPrevious()) {
12749  $data['previous'] = $this->normalizeException($previous);
12750  }
12751  return $data;
12752  }
12753  protected function toJson($data, $ignoreErrors = false)
12754  {
12755  if ($ignoreErrors) {
12756  if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
12757  return @json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
12758  }
12759  return @json_encode($data);
12760  }
12761  if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
12762  return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
12763  }
12764  return json_encode($data);
12765  }
12766 }
12767 namespace Monolog\Formatter;
12768 
12769 use Exception;
12771 {
12772  const SIMPLE_FORMAT = '[%datetime%] %channel%.%level_name%: %message% %context% %extra%
12773 ';
12774  protected $format;
12778  public function __construct($format = null, $dateFormat = null, $allowInlineLineBreaks = false, $ignoreEmptyContextAndExtra = false)
12779  {
12780  $this->format = $format ?: static::SIMPLE_FORMAT;
12781  $this->allowInlineLineBreaks = $allowInlineLineBreaks;
12782  $this->ignoreEmptyContextAndExtra = $ignoreEmptyContextAndExtra;
12783  parent::__construct($dateFormat);
12784  }
12785  public function includeStacktraces($include = true)
12786  {
12787  $this->includeStacktraces = $include;
12788  if ($this->includeStacktraces) {
12789  $this->allowInlineLineBreaks = true;
12790  }
12791  }
12792  public function allowInlineLineBreaks($allow = true)
12793  {
12794  $this->allowInlineLineBreaks = $allow;
12795  }
12796  public function ignoreEmptyContextAndExtra($ignore = true)
12797  {
12798  $this->ignoreEmptyContextAndExtra = $ignore;
12799  }
12800  public function format(array $record)
12801  {
12802  $vars = parent::format($record);
12803  $output = $this->format;
12804  foreach ($vars['extra'] as $var => $val) {
12805  if (false !== strpos($output, '%extra.' . $var . '%')) {
12806  $output = str_replace('%extra.' . $var . '%', $this->stringify($val), $output);
12807  unset($vars['extra'][$var]);
12808  }
12809  }
12810  if ($this->ignoreEmptyContextAndExtra) {
12811  if (empty($vars['context'])) {
12812  unset($vars['context']);
12813  $output = str_replace('%context%', '', $output);
12814  }
12815  if (empty($vars['extra'])) {
12816  unset($vars['extra']);
12817  $output = str_replace('%extra%', '', $output);
12818  }
12819  }
12820  foreach ($vars as $var => $val) {
12821  if (false !== strpos($output, '%' . $var . '%')) {
12822  $output = str_replace('%' . $var . '%', $this->stringify($val), $output);
12823  }
12824  }
12825  return $output;
12826  }
12827  public function formatBatch(array $records)
12828  {
12829  $message = '';
12830  foreach ($records as $record) {
12831  $message .= $this->format($record);
12832  }
12833  return $message;
12834  }
12835  public function stringify($value)
12836  {
12837  return $this->replaceNewlines($this->convertToString($value));
12838  }
12839  protected function normalizeException(Exception $e)
12840  {
12841  $previousText = '';
12842  if ($previous = $e->getPrevious()) {
12843  do {
12844  $previousText .= ', ' . get_class($previous) . '(code: ' . $previous->getCode() . '): ' . $previous->getMessage() . ' at ' . $previous->getFile() . ':' . $previous->getLine();
12845  } while ($previous = $previous->getPrevious());
12846  }
12847  $str = '[object] (' . get_class($e) . '(code: ' . $e->getCode() . '): ' . $e->getMessage() . ' at ' . $e->getFile() . ':' . $e->getLine() . $previousText . ')';
12848  if ($this->includeStacktraces) {
12849  $str .= '
12850 [stacktrace]
12851 ' . $e->getTraceAsString();
12852  }
12853  return $str;
12854  }
12855  protected function convertToString($data)
12856  {
12857  if (null === $data || is_bool($data)) {
12858  return var_export($data, true);
12859  }
12860  if (is_scalar($data)) {
12861  return (string) $data;
12862  }
12863  if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
12864  return $this->toJson($data, true);
12865  }
12866  return str_replace('\\/', '/', @json_encode($data));
12867  }
12868  protected function replaceNewlines($str)
12869  {
12870  if ($this->allowInlineLineBreaks) {
12871  return $str;
12872  }
12873  return strtr($str, array('
12874 ' => ' ', '
12875 ' => ' ', '
12876 ' => ' '));
12877  }
12878 }
12879 namespace Illuminate\Support\Facades;
12880 
12881 class App extends Facade
12882 {
12883  protected static function getFacadeAccessor()
12884  {
12885  return 'app';
12886  }
12887 }
12888 namespace Illuminate\Support\Facades;
12889 
12890 class Route extends Facade
12891 {
12892  protected static function getFacadeAccessor()
12893  {
12894  return 'router';
12895  }
12896 }
12898 
12899 use Closure;
12900 use InvalidArgumentException;
12902 {
12903  protected $resolvers = array();
12904  protected $resolved = array();
12905  public function register($engine, Closure $resolver)
12906  {
12907  unset($this->resolved[$engine]);
12908  $this->resolvers[$engine] = $resolver;
12909  }
12910  public function resolve($engine)
12911  {
12912  if (isset($this->resolved[$engine])) {
12913  return $this->resolved[$engine];
12914  }
12915  if (isset($this->resolvers[$engine])) {
12916  return $this->resolved[$engine] = call_user_func($this->resolvers[$engine]);
12917  }
12918  throw new InvalidArgumentException("Engine {$engine} not found.");
12919  }
12920 }
12921 namespace Illuminate\View;
12922 
12924 {
12925  const HINT_PATH_DELIMITER = '::';
12926  public function find($view);
12927  public function addLocation($location);
12928  public function addNamespace($namespace, $hints);
12929  public function prependNamespace($namespace, $hints);
12930  public function addExtension($extension);
12931 }
12932 namespace Illuminate\View;
12933 
12934 use InvalidArgumentException;
12937 {
12938  protected $files;
12939  protected $paths;
12940  protected $views = array();
12941  protected $hints = array();
12942  protected $extensions = array('blade.php', 'php');
12943  public function __construct(Filesystem $files, array $paths, array $extensions = null)
12944  {
12945  $this->files = $files;
12946  $this->paths = $paths;
12947  if (isset($extensions)) {
12948  $this->extensions = $extensions;
12949  }
12950  }
12951  public function find($name)
12952  {
12953  if (isset($this->views[$name])) {
12954  return $this->views[$name];
12955  }
12956  if ($this->hasHintInformation($name = trim($name))) {
12957  return $this->views[$name] = $this->findNamedPathView($name);
12958  }
12959  return $this->views[$name] = $this->findInPaths($name, $this->paths);
12960  }
12961  protected function findNamedPathView($name)
12962  {
12963  list($namespace, $view) = $this->getNamespaceSegments($name);
12964  return $this->findInPaths($view, $this->hints[$namespace]);
12965  }
12966  protected function getNamespaceSegments($name)
12967  {
12968  $segments = explode(static::HINT_PATH_DELIMITER, $name);
12969  if (count($segments) != 2) {
12970  throw new InvalidArgumentException("View [{$name}] has an invalid name.");
12971  }
12972  if (!isset($this->hints[$segments[0]])) {
12973  throw new InvalidArgumentException("No hint path defined for [{$segments[0]}].");
12974  }
12975  return $segments;
12976  }
12977  protected function findInPaths($name, $paths)
12978  {
12979  foreach ((array) $paths as $path) {
12980  foreach ($this->getPossibleViewFiles($name) as $file) {
12981  if ($this->files->exists($viewPath = $path . '/' . $file)) {
12982  return $viewPath;
12983  }
12984  }
12985  }
12986  throw new InvalidArgumentException("View [{$name}] not found.");
12987  }
12988  protected function getPossibleViewFiles($name)
12989  {
12990  return array_map(function ($extension) use($name) {
12991  return str_replace('.', '/', $name) . '.' . $extension;
12992  }, $this->extensions);
12993  }
12994  public function addLocation($location)
12995  {
12996  $this->paths[] = $location;
12997  }
12998  public function addNamespace($namespace, $hints)
12999  {
13000  $hints = (array) $hints;
13001  if (isset($this->hints[$namespace])) {
13002  $hints = array_merge($this->hints[$namespace], $hints);
13003  }
13004  $this->hints[$namespace] = $hints;
13005  }
13006  public function prependNamespace($namespace, $hints)
13007  {
13008  $hints = (array) $hints;
13009  if (isset($this->hints[$namespace])) {
13010  $hints = array_merge($hints, $this->hints[$namespace]);
13011  }
13012  $this->hints[$namespace] = $hints;
13013  }
13014  public function addExtension($extension)
13015  {
13016  if (($index = array_search($extension, $this->extensions)) !== false) {
13017  unset($this->extensions[$index]);
13018  }
13019  array_unshift($this->extensions, $extension);
13020  }
13021  public function hasHintInformation($name)
13022  {
13023  return strpos($name, static::HINT_PATH_DELIMITER) > 0;
13024  }
13025  public function getFilesystem()
13026  {
13027  return $this->files;
13028  }
13029  public function getPaths()
13030  {
13031  return $this->paths;
13032  }
13033  public function getHints()
13034  {
13035  return $this->hints;
13036  }
13037  public function getExtensions()
13038  {
13039  return $this->extensions;
13040  }
13041 }
13042 namespace Illuminate\View;
13043 
13044 use Closure;
13045 use InvalidArgumentException;
13051 class Factory implements FactoryContract
13052 {
13053  protected $engines;
13054  protected $finder;
13055  protected $events;
13056  protected $container;
13057  protected $shared = array();
13058  protected $aliases = array();
13059  protected $names = array();
13060  protected $extensions = array('blade.php' => 'blade', 'php' => 'php');
13061  protected $composers = array();
13062  protected $sections = array();
13063  protected $sectionStack = array();
13064  protected $renderCount = 0;
13065  public function __construct(EngineResolver $engines, ViewFinderInterface $finder, Dispatcher $events)
13066  {
13067  $this->finder = $finder;
13068  $this->events = $events;
13069  $this->engines = $engines;
13070  $this->share('__env', $this);
13071  }
13072  public function file($path, $data = array(), $mergeData = array())
13073  {
13074  $data = array_merge($mergeData, $this->parseData($data));
13075  $this->callCreator($view = new View($this, $this->getEngineFromPath($path), $path, $path, $data));
13076  return $view;
13077  }
13078  public function make($view, $data = array(), $mergeData = array())
13079  {
13080  if (isset($this->aliases[$view])) {
13081  $view = $this->aliases[$view];
13082  }
13083  $view = $this->normalizeName($view);
13084  $path = $this->finder->find($view);
13085  $data = array_merge($mergeData, $this->parseData($data));
13086  $this->callCreator($view = new View($this, $this->getEngineFromPath($path), $view, $path, $data));
13087  return $view;
13088  }
13089  protected function normalizeName($name)
13090  {
13091  $delimiter = ViewFinderInterface::HINT_PATH_DELIMITER;
13092  if (strpos($name, $delimiter) === false) {
13093  return str_replace('/', '.', $name);
13094  }
13095  list($namespace, $name) = explode($delimiter, $name);
13096  return $namespace . $delimiter . str_replace('/', '.', $name);
13097  }
13098  protected function parseData($data)
13099  {
13100  return $data instanceof Arrayable ? $data->toArray() : $data;
13101  }
13102  public function of($view, $data = array())
13103  {
13104  return $this->make($this->names[$view], $data);
13105  }
13106  public function name($view, $name)
13107  {
13108  $this->names[$name] = $view;
13109  }
13110  public function alias($view, $alias)
13111  {
13112  $this->aliases[$alias] = $view;
13113  }
13114  public function exists($view)
13115  {
13116  try {
13117  $this->finder->find($view);
13118  } catch (InvalidArgumentException $e) {
13119  return false;
13120  }
13121  return true;
13122  }
13123  public function renderEach($view, $data, $iterator, $empty = 'raw|')
13124  {
13125  $result = '';
13126  if (count($data) > 0) {
13127  foreach ($data as $key => $value) {
13128  $data = array('key' => $key, $iterator => $value);
13129  $result .= $this->make($view, $data)->render();
13130  }
13131  } else {
13132  if (starts_with($empty, 'raw|')) {
13133  $result = substr($empty, 4);
13134  } else {
13135  $result = $this->make($empty)->render();
13136  }
13137  }
13138  return $result;
13139  }
13140  public function getEngineFromPath($path)
13141  {
13142  if (!($extension = $this->getExtension($path))) {
13143  throw new InvalidArgumentException("Unrecognized extension in file: {$path}");
13144  }
13145  $engine = $this->extensions[$extension];
13146  return $this->engines->resolve($engine);
13147  }
13148  protected function getExtension($path)
13149  {
13150  $extensions = array_keys($this->extensions);
13151  return array_first($extensions, function ($key, $value) use($path) {
13152  return ends_with($path, $value);
13153  });
13154  }
13155  public function share($key, $value = null)
13156  {
13157  if (!is_array($key)) {
13158  return $this->shared[$key] = $value;
13159  }
13160  foreach ($key as $innerKey => $innerValue) {
13161  $this->share($innerKey, $innerValue);
13162  }
13163  }
13164  public function creator($views, $callback)
13165  {
13166  $creators = array();
13167  foreach ((array) $views as $view) {
13168  $creators[] = $this->addViewEvent($view, $callback, 'creating: ');
13169  }
13170  return $creators;
13171  }
13172  public function composers(array $composers)
13173  {
13174  $registered = array();
13175  foreach ($composers as $callback => $views) {
13176  $registered = array_merge($registered, $this->composer($views, $callback));
13177  }
13178  return $registered;
13179  }
13180  public function composer($views, $callback, $priority = null)
13181  {
13182  $composers = array();
13183  foreach ((array) $views as $view) {
13184  $composers[] = $this->addViewEvent($view, $callback, 'composing: ', $priority);
13185  }
13186  return $composers;
13187  }
13188  protected function addViewEvent($view, $callback, $prefix = 'composing: ', $priority = null)
13189  {
13190  $view = $this->normalizeName($view);
13191  if ($callback instanceof Closure) {
13192  $this->addEventListener($prefix . $view, $callback, $priority);
13193  return $callback;
13194  } elseif (is_string($callback)) {
13195  return $this->addClassEvent($view, $callback, $prefix, $priority);
13196  }
13197  }
13198  protected function addClassEvent($view, $class, $prefix, $priority = null)
13199  {
13200  $name = $prefix . $view;
13201  $callback = $this->buildClassEventCallback($class, $prefix);
13202  $this->addEventListener($name, $callback, $priority);
13203  return $callback;
13204  }
13205  protected function addEventListener($name, $callback, $priority = null)
13206  {
13207  if (is_null($priority)) {
13208  $this->events->listen($name, $callback);
13209  } else {
13210  $this->events->listen($name, $callback, $priority);
13211  }
13212  }
13213  protected function buildClassEventCallback($class, $prefix)
13214  {
13215  list($class, $method) = $this->parseClassEvent($class, $prefix);
13216  return function () use($class, $method) {
13217  $callable = array($this->container->make($class), $method);
13218  return call_user_func_array($callable, func_get_args());
13219  };
13220  }
13221  protected function parseClassEvent($class, $prefix)
13222  {
13223  if (str_contains($class, '@')) {
13224  return explode('@', $class);
13225  }
13226  $method = str_contains($prefix, 'composing') ? 'compose' : 'create';
13227  return array($class, $method);
13228  }
13229  public function callComposer(View $view)
13230  {
13231  $this->events->fire('composing: ' . $view->getName(), array($view));
13232  }
13233  public function callCreator(View $view)
13234  {
13235  $this->events->fire('creating: ' . $view->getName(), array($view));
13236  }
13237  public function startSection($section, $content = '')
13238  {
13239  if ($content === '') {
13240  if (ob_start()) {
13241  $this->sectionStack[] = $section;
13242  }
13243  } else {
13244  $this->extendSection($section, $content);
13245  }
13246  }
13247  public function inject($section, $content)
13248  {
13249  return $this->startSection($section, $content);
13250  }
13251  public function yieldSection()
13252  {
13253  return $this->yieldContent($this->stopSection());
13254  }
13255  public function stopSection($overwrite = false)
13256  {
13257  $last = array_pop($this->sectionStack);
13258  if ($overwrite) {
13259  $this->sections[$last] = ob_get_clean();
13260  } else {
13261  $this->extendSection($last, ob_get_clean());
13262  }
13263  return $last;
13264  }
13265  public function appendSection()
13266  {
13267  $last = array_pop($this->sectionStack);
13268  if (isset($this->sections[$last])) {
13269  $this->sections[$last] .= ob_get_clean();
13270  } else {
13271  $this->sections[$last] = ob_get_clean();
13272  }
13273  return $last;
13274  }
13275  protected function extendSection($section, $content)
13276  {
13277  if (isset($this->sections[$section])) {
13278  $content = str_replace('@parent', $content, $this->sections[$section]);
13279  }
13280  $this->sections[$section] = $content;
13281  }
13282  public function yieldContent($section, $default = '')
13283  {
13284  $sectionContent = $default;
13285  if (isset($this->sections[$section])) {
13286  $sectionContent = $this->sections[$section];
13287  }
13288  $sectionContent = str_replace('@@parent', '--parent--holder--', $sectionContent);
13289  return str_replace('--parent--holder--', '@parent', str_replace('@parent', '', $sectionContent));
13290  }
13291  public function flushSections()
13292  {
13293  $this->sections = array();
13294  $this->sectionStack = array();
13295  }
13297  {
13298  if ($this->doneRendering()) {
13299  $this->flushSections();
13300  }
13301  }
13302  public function incrementRender()
13303  {
13304  $this->renderCount++;
13305  }
13306  public function decrementRender()
13307  {
13308  $this->renderCount--;
13309  }
13310  public function doneRendering()
13311  {
13312  return $this->renderCount == 0;
13313  }
13314  public function addLocation($location)
13315  {
13316  $this->finder->addLocation($location);
13317  }
13318  public function addNamespace($namespace, $hints)
13319  {
13320  $this->finder->addNamespace($namespace, $hints);
13321  }
13322  public function prependNamespace($namespace, $hints)
13323  {
13324  $this->finder->prependNamespace($namespace, $hints);
13325  }
13326  public function addExtension($extension, $engine, $resolver = null)
13327  {
13328  $this->finder->addExtension($extension);
13329  if (isset($resolver)) {
13330  $this->engines->register($engine, $resolver);
13331  }
13332  unset($this->extensions[$extension]);
13333  $this->extensions = array_merge(array($extension => $engine), $this->extensions);
13334  }
13335  public function getExtensions()
13336  {
13337  return $this->extensions;
13338  }
13339  public function getEngineResolver()
13340  {
13341  return $this->engines;
13342  }
13343  public function getFinder()
13344  {
13345  return $this->finder;
13346  }
13347  public function setFinder(ViewFinderInterface $finder)
13348  {
13349  $this->finder = $finder;
13350  }
13351  public function getDispatcher()
13352  {
13353  return $this->events;
13354  }
13355  public function setDispatcher(Dispatcher $events)
13356  {
13357  $this->events = $events;
13358  }
13359  public function getContainer()
13360  {
13361  return $this->container;
13362  }
13364  {
13365  $this->container = $container;
13366  }
13367  public function shared($key, $default = null)
13368  {
13369  return array_get($this->shared, $key, $default);
13370  }
13371  public function getShared()
13372  {
13373  return $this->shared;
13374  }
13375  public function getSections()
13376  {
13377  return $this->sections;
13378  }
13379  public function getNames()
13380  {
13381  return $this->names;
13382  }
13383 }
13384 namespace Illuminate\Support;
13385 
13386 use Countable;
13387 use Illuminate\Contracts\Support\MessageBag as MessageBagContract;
13388 class ViewErrorBag implements Countable
13389 {
13390  protected $bags = array();
13391  public function hasBag($key = 'default')
13392  {
13393  return isset($this->bags[$key]);
13394  }
13395  public function getBag($key)
13396  {
13397  return array_get($this->bags, $key, new MessageBag());
13398  }
13399  public function getBags()
13400  {
13401  return $this->bags;
13402  }
13403  public function put($key, MessageBagContract $bag)
13404  {
13405  $this->bags[$key] = $bag;
13406  return $this;
13407  }
13408  public function count()
13409  {
13410  return $this->default->count();
13411  }
13412  public function __call($method, $parameters)
13413  {
13414  return call_user_func_array(array($this->default, $method), $parameters);
13415  }
13416  public function __get($key)
13417  {
13418  return array_get($this->bags, $key, new MessageBag());
13419  }
13420  public function __set($key, $value)
13421  {
13422  array_set($this->bags, $key, $value);
13423  }
13424 }
13425 namespace Illuminate\Support;
13426 
13427 use Countable;
13428 use JsonSerializable;
13432 use Illuminate\Contracts\Support\MessageBag as MessageBagContract;
13433 class MessageBag implements Arrayable, Countable, Jsonable, JsonSerializable, MessageBagContract, MessageProvider
13434 {
13435  protected $messages = array();
13436  protected $format = ':message';
13437  public function __construct(array $messages = array())
13438  {
13439  foreach ($messages as $key => $value) {
13440  $this->messages[$key] = (array) $value;
13441  }
13442  }
13443  public function keys()
13444  {
13445  return array_keys($this->messages);
13446  }
13447  public function add($key, $message)
13448  {
13449  if ($this->isUnique($key, $message)) {
13450  $this->messages[$key][] = $message;
13451  }
13452  return $this;
13453  }
13454  public function merge($messages)
13455  {
13456  if ($messages instanceof MessageProvider) {
13457  $messages = $messages->getMessageBag()->getMessages();
13458  }
13459  $this->messages = array_merge_recursive($this->messages, $messages);
13460  return $this;
13461  }
13462  protected function isUnique($key, $message)
13463  {
13464  $messages = (array) $this->messages;
13465  return !isset($messages[$key]) || !in_array($message, $messages[$key]);
13466  }
13467  public function has($key = null)
13468  {
13469  return $this->first($key) !== '';
13470  }
13471  public function first($key = null, $format = null)
13472  {
13473  $messages = is_null($key) ? $this->all($format) : $this->get($key, $format);
13474  return count($messages) > 0 ? $messages[0] : '';
13475  }
13476  public function get($key, $format = null)
13477  {
13478  $format = $this->checkFormat($format);
13479  if (array_key_exists($key, $this->messages)) {
13480  return $this->transform($this->messages[$key], $format, $key);
13481  }
13482  return array();
13483  }
13484  public function all($format = null)
13485  {
13486  $format = $this->checkFormat($format);
13487  $all = array();
13488  foreach ($this->messages as $key => $messages) {
13489  $all = array_merge($all, $this->transform($messages, $format, $key));
13490  }
13491  return $all;
13492  }
13493  protected function transform($messages, $format, $messageKey)
13494  {
13495  $messages = (array) $messages;
13496  foreach ($messages as &$message) {
13497  $replace = array(':message', ':key');
13498  $message = str_replace($replace, array($message, $messageKey), $format);
13499  }
13500  return $messages;
13501  }
13502  protected function checkFormat($format)
13503  {
13504  return $format ?: $this->format;
13505  }
13506  public function getMessages()
13507  {
13508  return $this->messages;
13509  }
13510  public function getMessageBag()
13511  {
13512  return $this;
13513  }
13514  public function getFormat()
13515  {
13516  return $this->format;
13517  }
13518  public function setFormat($format = ':message')
13519  {
13520  $this->format = $format;
13521  return $this;
13522  }
13523  public function isEmpty()
13524  {
13525  return !$this->any();
13526  }
13527  public function any()
13528  {
13529  return $this->count() > 0;
13530  }
13531  public function count()
13532  {
13533  return count($this->messages, COUNT_RECURSIVE) - count($this->messages);
13534  }
13535  public function toArray()
13536  {
13537  return $this->getMessages();
13538  }
13539  public function jsonSerialize()
13540  {
13541  return $this->toArray();
13542  }
13543  public function toJson($options = 0)
13544  {
13545  return json_encode($this->toArray(), $options);
13546  }
13547  public function __toString()
13548  {
13549  return $this->toJson();
13550  }
13551 }
13552 namespace Illuminate\Support\Facades;
13553 
13554 class View extends Facade
13555 {
13556  protected static function getFacadeAccessor()
13557  {
13558  return 'view';
13559  }
13560 }
13561 namespace Illuminate\View;
13562 
13563 use Closure;
13564 use ArrayAccess;
13565 use BadMethodCallException;
13571 use Illuminate\Contracts\View\View as ViewContract;
13572 class View implements ArrayAccess, ViewContract
13573 {
13574  protected $factory;
13575  protected $engine;
13576  protected $view;
13577  protected $data;
13578  protected $path;
13579  public function __construct(Factory $factory, EngineInterface $engine, $view, $path, $data = array())
13580  {
13581  $this->view = $view;
13582  $this->path = $path;
13583  $this->engine = $engine;
13584  $this->factory = $factory;
13585  $this->data = $data instanceof Arrayable ? $data->toArray() : (array) $data;
13586  }
13587  public function render(Closure $callback = null)
13588  {
13589  $contents = $this->renderContents();
13590  $response = isset($callback) ? $callback($this, $contents) : null;
13591  $this->factory->flushSectionsIfDoneRendering();
13592  return $response ?: $contents;
13593  }
13594  protected function renderContents()
13595  {
13596  $this->factory->incrementRender();
13597  $this->factory->callComposer($this);
13598  $contents = $this->getContents();
13599  $this->factory->decrementRender();
13600  return $contents;
13601  }
13602  public function renderSections()
13603  {
13604  $env = $this->factory;
13605  return $this->render(function ($view) use($env) {
13606  return $env->getSections();
13607  });
13608  }
13609  protected function getContents()
13610  {
13611  return $this->engine->get($this->path, $this->gatherData());
13612  }
13613  protected function gatherData()
13614  {
13615  $data = array_merge($this->factory->getShared(), $this->data);
13616  foreach ($data as $key => $value) {
13617  if ($value instanceof Renderable) {
13618  $data[$key] = $value->render();
13619  }
13620  }
13621  return $data;
13622  }
13623  public function with($key, $value = null)
13624  {
13625  if (is_array($key)) {
13626  $this->data = array_merge($this->data, $key);
13627  } else {
13628  $this->data[$key] = $value;
13629  }
13630  return $this;
13631  }
13632  public function nest($key, $view, array $data = array())
13633  {
13634  return $this->with($key, $this->factory->make($view, $data));
13635  }
13636  public function withErrors($provider)
13637  {
13638  if ($provider instanceof MessageProvider) {
13639  $this->with('errors', $provider->getMessageBag());
13640  } else {
13641  $this->with('errors', new MessageBag((array) $provider));
13642  }
13643  return $this;
13644  }
13645  public function getFactory()
13646  {
13647  return $this->factory;
13648  }
13649  public function getEngine()
13650  {
13651  return $this->engine;
13652  }
13653  public function name()
13654  {
13655  return $this->getName();
13656  }
13657  public function getName()
13658  {
13659  return $this->view;
13660  }
13661  public function getData()
13662  {
13663  return $this->data;
13664  }
13665  public function getPath()
13666  {
13667  return $this->path;
13668  }
13669  public function setPath($path)
13670  {
13671  $this->path = $path;
13672  }
13673  public function offsetExists($key)
13674  {
13675  return array_key_exists($key, $this->data);
13676  }
13677  public function offsetGet($key)
13678  {
13679  return $this->data[$key];
13680  }
13681  public function offsetSet($key, $value)
13682  {
13683  $this->with($key, $value);
13684  }
13685  public function offsetUnset($key)
13686  {
13687  unset($this->data[$key]);
13688  }
13689  public function &__get($key)
13690  {
13691  return $this->data[$key];
13692  }
13693  public function __set($key, $value)
13694  {
13695  $this->with($key, $value);
13696  }
13697  public function __isset($key)
13698  {
13699  return isset($this->data[$key]);
13700  }
13701  public function __unset($key)
13702  {
13703  unset($this->data[$key]);
13704  }
13705  public function __call($method, $parameters)
13706  {
13707  if (starts_with($method, 'with')) {
13708  return $this->with(snake_case(substr($method, 4)), $parameters[0]);
13709  }
13710  throw new BadMethodCallException("Method [{$method}] does not exist on view.");
13711  }
13712  public function __toString()
13713  {
13714  return $this->render();
13715  }
13716 }
13717 namespace Illuminate\View\Engines;
13718 
13720 {
13721  public function get($path, array $data = array());
13722 }
13723 namespace Illuminate\View\Engines;
13724 
13725 use Exception;
13726 class PhpEngine implements EngineInterface
13727 {
13728  public function get($path, array $data = array())
13729  {
13730  return $this->evaluatePath($path, $data);
13731  }
13732  protected function evaluatePath($__path, $__data)
13733  {
13734  $obLevel = ob_get_level();
13735  ob_start();
13736  extract($__data);
13737  try {
13738  include $__path;
13739  } catch (Exception $e) {
13740  $this->handleViewException($e, $obLevel);
13741  }
13742  return ltrim(ob_get_clean());
13743  }
13744  protected function handleViewException($e, $obLevel)
13745  {
13746  while (ob_get_level() > $obLevel) {
13747  ob_end_clean();
13748  }
13749  throw $e;
13750  }
13751 }
13752 namespace Illuminate\View\Engines;
13753 
13754 use ErrorException;
13757 {
13758  protected $compiler;
13759  protected $lastCompiled = array();
13760  public function __construct(CompilerInterface $compiler)
13761  {
13762  $this->compiler = $compiler;
13763  }
13764  public function get($path, array $data = array())
13765  {
13766  $this->lastCompiled[] = $path;
13767  if ($this->compiler->isExpired($path)) {
13768  $this->compiler->compile($path);
13769  }
13770  $compiled = $this->compiler->getCompiledPath($path);
13771  $results = $this->evaluatePath($compiled, $data);
13772  array_pop($this->lastCompiled);
13773  return $results;
13774  }
13775  protected function handleViewException($e, $obLevel)
13776  {
13777  $e = new ErrorException($this->getMessage($e), 0, 1, $e->getFile(), $e->getLine(), $e);
13778  parent::handleViewException($e, $obLevel);
13779  }
13780  protected function getMessage($e)
13781  {
13782  return $e->getMessage() . ' (View: ' . realpath(last($this->lastCompiled)) . ')';
13783  }
13784  public function getCompiler()
13785  {
13786  return $this->compiler;
13787  }
13788 }
13790 
13792 {
13793  public function getCompiledPath($path);
13794  public function isExpired($path);
13795  public function compile($path);
13796 }
13797 namespace Illuminate\View\Compilers;
13798 
13800 abstract class Compiler
13801 {
13802  protected $files;
13803  protected $cachePath;
13804  public function __construct(Filesystem $files, $cachePath)
13805  {
13806  $this->files = $files;
13807  $this->cachePath = $cachePath;
13808  }
13809  public function getCompiledPath($path)
13810  {
13811  return $this->cachePath . '/' . md5($path);
13812  }
13813  public function isExpired($path)
13814  {
13815  $compiled = $this->getCompiledPath($path);
13816  if (!$this->cachePath || !$this->files->exists($compiled)) {
13817  return true;
13818  }
13819  $lastModified = $this->files->lastModified($path);
13820  return $lastModified >= $this->files->lastModified($compiled);
13821  }
13822 }
13823 namespace Illuminate\View\Compilers;
13824 
13825 class BladeCompiler extends Compiler implements CompilerInterface
13826 {
13827  protected $extensions = array();
13828  protected $path;
13829  protected $compilers = array('Extensions', 'Statements', 'Comments', 'Echos');
13830  protected $rawTags = array('{!!', '!!}');
13831  protected $contentTags = array('{{', '}}');
13832  protected $escapedTags = array('{{{', '}}}');
13833  protected $echoFormat = 'e(%s)';
13834  protected $footer = array();
13835  protected $forelseCounter = 0;
13836  public function compile($path = null)
13837  {
13838  $this->footer = array();
13839  if ($path) {
13840  $this->setPath($path);
13841  }
13842  $contents = $this->compileString($this->files->get($path));
13843  if (!is_null($this->cachePath)) {
13844  $this->files->put($this->getCompiledPath($this->getPath()), $contents);
13845  }
13846  }
13847  public function getPath()
13848  {
13849  return $this->path;
13850  }
13851  public function setPath($path)
13852  {
13853  $this->path = $path;
13854  }
13855  public function compileString($value)
13856  {
13857  $result = '';
13858  foreach (token_get_all($value) as $token) {
13859  $result .= is_array($token) ? $this->parseToken($token) : $token;
13860  }
13861  if (count($this->footer) > 0) {
13862  $result = ltrim($result, PHP_EOL) . PHP_EOL . implode(PHP_EOL, array_reverse($this->footer));
13863  }
13864  return $result;
13865  }
13866  protected function parseToken($token)
13867  {
13868  list($id, $content) = $token;
13869  if ($id == T_INLINE_HTML) {
13870  foreach ($this->compilers as $type) {
13871  $content = $this->{"compile{$type}"}($content);
13872  }
13873  }
13874  return $content;
13875  }
13876  protected function compileExtensions($value)
13877  {
13878  foreach ($this->extensions as $compiler) {
13879  $value = call_user_func($compiler, $value, $this);
13880  }
13881  return $value;
13882  }
13883  protected function compileComments($value)
13884  {
13885  $pattern = sprintf('/%s--((.|\\s)*?)--%s/', $this->contentTags[0], $this->contentTags[1]);
13886  return preg_replace($pattern, '<?php /*$1*/ ?>', $value);
13887  }
13888  protected function compileEchos($value)
13889  {
13890  foreach ($this->getEchoMethods() as $method => $length) {
13891  $value = $this->{$method}($value);
13892  }
13893  return $value;
13894  }
13895  protected function getEchoMethods()
13896  {
13897  $methods = array('compileRawEchos' => strlen(stripcslashes($this->rawTags[0])), 'compileEscapedEchos' => strlen(stripcslashes($this->escapedTags[0])), 'compileRegularEchos' => strlen(stripcslashes($this->contentTags[0])));
13898  uksort($methods, function ($method1, $method2) use($methods) {
13899  if ($methods[$method1] > $methods[$method2]) {
13900  return -1;
13901  }
13902  if ($methods[$method1] < $methods[$method2]) {
13903  return 1;
13904  }
13905  if ($method1 === 'compileRawEchos') {
13906  return -1;
13907  }
13908  if ($method2 === 'compileRawEchos') {
13909  return 1;
13910  }
13911  if ($method1 === 'compileEscapedEchos') {
13912  return -1;
13913  }
13914  if ($method2 === 'compileEscapedEchos') {
13915  return 1;
13916  }
13917  });
13918  return $methods;
13919  }
13920  protected function compileStatements($value)
13921  {
13922  $callback = function ($match) {
13923  if (method_exists($this, $method = 'compile' . ucfirst($match[1]))) {
13924  $match[0] = $this->{$method}(array_get($match, 3));
13925  }
13926  return isset($match[3]) ? $match[0] : $match[0] . $match[2];
13927  };
13928  return preg_replace_callback('/\\B@(\\w+)([ \\t]*)(\\( ( (?>[^()]+) | (?3) )* \\))?/x', $callback, $value);
13929  }
13930  protected function compileRawEchos($value)
13931  {
13932  $pattern = sprintf('/(@)?%s\\s*(.+?)\\s*%s(\\r?\\n)?/s', $this->rawTags[0], $this->rawTags[1]);
13933  $callback = function ($matches) {
13934  $whitespace = empty($matches[3]) ? '' : $matches[3] . $matches[3];
13935  return $matches[1] ? substr($matches[0], 1) : '<?php echo ' . $this->compileEchoDefaults($matches[2]) . '; ?>' . $whitespace;
13936  };
13937  return preg_replace_callback($pattern, $callback, $value);
13938  }
13939  protected function compileRegularEchos($value)
13940  {
13941  $pattern = sprintf('/(@)?%s\\s*(.+?)\\s*%s(\\r?\\n)?/s', $this->contentTags[0], $this->contentTags[1]);
13942  $callback = function ($matches) {
13943  $whitespace = empty($matches[3]) ? '' : $matches[3] . $matches[3];
13944  $wrapped = sprintf($this->echoFormat, $this->compileEchoDefaults($matches[2]));
13945  return $matches[1] ? substr($matches[0], 1) : '<?php echo ' . $wrapped . '; ?>' . $whitespace;
13946  };
13947  return preg_replace_callback($pattern, $callback, $value);
13948  }
13949  protected function compileEscapedEchos($value)
13950  {
13951  $pattern = sprintf('/%s\\s*(.+?)\\s*%s(\\r?\\n)?/s', $this->escapedTags[0], $this->escapedTags[1]);
13952  $callback = function ($matches) {
13953  $whitespace = empty($matches[2]) ? '' : $matches[2] . $matches[2];
13954  return '<?php echo e(' . $this->compileEchoDefaults($matches[1]) . '); ?>' . $whitespace;
13955  };
13956  return preg_replace_callback($pattern, $callback, $value);
13957  }
13958  public function compileEchoDefaults($value)
13959  {
13960  return preg_replace('/^(?=\\$)(.+?)(?:\\s+or\\s+)(.+?)$/s', 'isset($1) ? $1 : $2', $value);
13961  }
13962  protected function compileEach($expression)
13963  {
13964  return "<?php echo \$__env->renderEach{$expression}; ?>";
13965  }
13966  protected function compileYield($expression)
13967  {
13968  return "<?php echo \$__env->yieldContent{$expression}; ?>";
13969  }
13970  protected function compileShow($expression)
13971  {
13972  return '<?php echo $__env->yieldSection(); ?>';
13973  }
13974  protected function compileSection($expression)
13975  {
13976  return "<?php \$__env->startSection{$expression}; ?>";
13977  }
13978  protected function compileAppend($expression)
13979  {
13980  return '<?php $__env->appendSection(); ?>';
13981  }
13982  protected function compileEndsection($expression)
13983  {
13984  return '<?php $__env->stopSection(); ?>';
13985  }
13986  protected function compileStop($expression)
13987  {
13988  return '<?php $__env->stopSection(); ?>';
13989  }
13990  protected function compileOverwrite($expression)
13991  {
13992  return '<?php $__env->stopSection(true); ?>';
13993  }
13994  protected function compileUnless($expression)
13995  {
13996  return "<?php if ( ! {$expression}): ?>";
13997  }
13998  protected function compileEndunless($expression)
13999  {
14000  return '<?php endif; ?>';
14001  }
14002  protected function compileLang($expression)
14003  {
14004  return "<?php echo \\Illuminate\\Support\\Facades\\Lang::get{$expression}; ?>";
14005  }
14006  protected function compileChoice($expression)
14007  {
14008  return "<?php echo \\Illuminate\\Support\\Facades\\Lang::choice{$expression}; ?>";
14009  }
14010  protected function compileElse($expression)
14011  {
14012  return '<?php else: ?>';
14013  }
14014  protected function compileFor($expression)
14015  {
14016  return "<?php for{$expression}: ?>";
14017  }
14018  protected function compileForeach($expression)
14019  {
14020  return "<?php foreach{$expression}: ?>";
14021  }
14022  protected function compileForelse($expression)
14023  {
14024  $empty = '$__empty_' . ++$this->forelseCounter;
14025  return "<?php {$empty} = true; foreach{$expression}: {$empty} = false; ?>";
14026  }
14027  protected function compileIf($expression)
14028  {
14029  return "<?php if{$expression}: ?>";
14030  }
14031  protected function compileElseif($expression)
14032  {
14033  return "<?php elseif{$expression}: ?>";
14034  }
14035  protected function compileEmpty($expression)
14036  {
14037  $empty = '$__empty_' . $this->forelseCounter--;
14038  return "<?php endforeach; if ({$empty}): ?>";
14039  }
14040  protected function compileWhile($expression)
14041  {
14042  return "<?php while{$expression}: ?>";
14043  }
14044  protected function compileEndwhile($expression)
14045  {
14046  return '<?php endwhile; ?>';
14047  }
14048  protected function compileEndfor($expression)
14049  {
14050  return '<?php endfor; ?>';
14051  }
14052  protected function compileEndforeach($expression)
14053  {
14054  return '<?php endforeach; ?>';
14055  }
14056  protected function compileEndif($expression)
14057  {
14058  return '<?php endif; ?>';
14059  }
14060  protected function compileEndforelse($expression)
14061  {
14062  return '<?php endif; ?>';
14063  }
14064  protected function compileExtends($expression)
14065  {
14066  if (starts_with($expression, '(')) {
14067  $expression = substr($expression, 1, -1);
14068  }
14069  $data = "<?php echo \$__env->make({$expression}, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>";
14070  $this->footer[] = $data;
14071  return '';
14072  }
14073  protected function compileInclude($expression)
14074  {
14075  if (starts_with($expression, '(')) {
14076  $expression = substr($expression, 1, -1);
14077  }
14078  return "<?php echo \$__env->make({$expression}, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>";
14079  }
14080  protected function compileStack($expression)
14081  {
14082  return "<?php echo \$__env->yieldContent{$expression}; ?>";
14083  }
14084  protected function compilePush($expression)
14085  {
14086  return "<?php \$__env->startSection{$expression}; ?>";
14087  }
14088  protected function compileEndpush($expression)
14089  {
14090  return '<?php $__env->appendSection(); ?>';
14091  }
14092  public function extend(callable $compiler)
14093  {
14094  $this->extensions[] = $compiler;
14095  }
14096  public function createMatcher($function)
14097  {
14098  return '/(?<!\\w)(\\s*)@' . $function . '(\\s*\\(.*\\))/';
14099  }
14100  public function createOpenMatcher($function)
14101  {
14102  return '/(?<!\\w)(\\s*)@' . $function . '(\\s*\\(.*)\\)/';
14103  }
14104  public function createPlainMatcher($function)
14105  {
14106  return '/(?<!\\w)(\\s*)@' . $function . '(\\s*)/';
14107  }
14108  public function setRawTags($openTag, $closeTag)
14109  {
14110  $this->rawTags = array(preg_quote($openTag), preg_quote($closeTag));
14111  }
14112  public function setContentTags($openTag, $closeTag, $escaped = false)
14113  {
14114  $property = $escaped === true ? 'escapedTags' : 'contentTags';
14115  $this->{$property} = array(preg_quote($openTag), preg_quote($closeTag));
14116  }
14117  public function setEscapedContentTags($openTag, $closeTag)
14118  {
14119  $this->setContentTags($openTag, $closeTag, true);
14120  }
14121  public function getContentTags()
14122  {
14123  return $this->getTags();
14124  }
14125  public function getEscapedContentTags()
14126  {
14127  return $this->getTags(true);
14128  }
14129  protected function getTags($escaped = false)
14130  {
14131  $tags = $escaped ? $this->escapedTags : $this->contentTags;
14132  return array_map('stripcslashes', $tags);
14133  }
14134  public function setEchoFormat($format)
14135  {
14136  $this->echoFormat = $format;
14137  }
14138 }
14140 
14142 {
14143  const HTTP_CONTINUE = 100;
14144  const HTTP_SWITCHING_PROTOCOLS = 101;
14145  const HTTP_PROCESSING = 102;
14146  const HTTP_OK = 200;
14147  const HTTP_CREATED = 201;
14148  const HTTP_ACCEPTED = 202;
14149  const HTTP_NON_AUTHORITATIVE_INFORMATION = 203;
14150  const HTTP_NO_CONTENT = 204;
14151  const HTTP_RESET_CONTENT = 205;
14152  const HTTP_PARTIAL_CONTENT = 206;
14153  const HTTP_MULTI_STATUS = 207;
14154  const HTTP_ALREADY_REPORTED = 208;
14155  const HTTP_IM_USED = 226;
14156  const HTTP_MULTIPLE_CHOICES = 300;
14157  const HTTP_MOVED_PERMANENTLY = 301;
14158  const HTTP_FOUND = 302;
14159  const HTTP_SEE_OTHER = 303;
14160  const HTTP_NOT_MODIFIED = 304;
14161  const HTTP_USE_PROXY = 305;
14162  const HTTP_RESERVED = 306;
14163  const HTTP_TEMPORARY_REDIRECT = 307;
14164  const HTTP_PERMANENTLY_REDIRECT = 308;
14165  const HTTP_BAD_REQUEST = 400;
14166  const HTTP_UNAUTHORIZED = 401;
14167  const HTTP_PAYMENT_REQUIRED = 402;
14168  const HTTP_FORBIDDEN = 403;
14169  const HTTP_NOT_FOUND = 404;
14170  const HTTP_METHOD_NOT_ALLOWED = 405;
14171  const HTTP_NOT_ACCEPTABLE = 406;
14172  const HTTP_PROXY_AUTHENTICATION_REQUIRED = 407;
14173  const HTTP_REQUEST_TIMEOUT = 408;
14174  const HTTP_CONFLICT = 409;
14175  const HTTP_GONE = 410;
14176  const HTTP_LENGTH_REQUIRED = 411;
14177  const HTTP_PRECONDITION_FAILED = 412;
14178  const HTTP_REQUEST_ENTITY_TOO_LARGE = 413;
14179  const HTTP_REQUEST_URI_TOO_LONG = 414;
14180  const HTTP_UNSUPPORTED_MEDIA_TYPE = 415;
14181  const HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
14182  const HTTP_EXPECTATION_FAILED = 417;
14183  const HTTP_I_AM_A_TEAPOT = 418;
14184  const HTTP_UNPROCESSABLE_ENTITY = 422;
14185  const HTTP_LOCKED = 423;
14186  const HTTP_FAILED_DEPENDENCY = 424;
14187  const HTTP_RESERVED_FOR_WEBDAV_ADVANCED_COLLECTIONS_EXPIRED_PROPOSAL = 425;
14188  const HTTP_UPGRADE_REQUIRED = 426;
14189  const HTTP_PRECONDITION_REQUIRED = 428;
14190  const HTTP_TOO_MANY_REQUESTS = 429;
14191  const HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431;
14192  const HTTP_INTERNAL_SERVER_ERROR = 500;
14193  const HTTP_NOT_IMPLEMENTED = 501;
14194  const HTTP_BAD_GATEWAY = 502;
14195  const HTTP_SERVICE_UNAVAILABLE = 503;
14196  const HTTP_GATEWAY_TIMEOUT = 504;
14197  const HTTP_VERSION_NOT_SUPPORTED = 505;
14198  const HTTP_VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL = 506;
14199  const HTTP_INSUFFICIENT_STORAGE = 507;
14200  const HTTP_LOOP_DETECTED = 508;
14201  const HTTP_NOT_EXTENDED = 510;
14202  const HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511;
14203  public $headers;
14204  protected $content;
14205  protected $version;
14206  protected $statusCode;
14207  protected $statusText;
14208  protected $charset;
14209  public static $statusTexts = array(100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 207 => 'Multi-Status', 208 => 'Already Reported', 226 => 'IM Used', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 306 => 'Reserved', 307 => 'Temporary Redirect', 308 => 'Permanent Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 418 => 'I\'m a teapot', 422 => 'Unprocessable Entity', 423 => 'Locked', 424 => 'Failed Dependency', 425 => 'Reserved for WebDAV advanced collections expired proposal', 426 => 'Upgrade Required', 428 => 'Precondition Required', 429 => 'Too Many Requests', 431 => 'Request Header Fields Too Large', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported', 506 => 'Variant Also Negotiates (Experimental)', 507 => 'Insufficient Storage', 508 => 'Loop Detected', 510 => 'Not Extended', 511 => 'Network Authentication Required');
14210  public function __construct($content = '', $status = 200, $headers = array())
14211  {
14212  $this->headers = new ResponseHeaderBag($headers);
14213  $this->setContent($content);
14214  $this->setStatusCode($status);
14215  $this->setProtocolVersion('1.0');
14216  if (!$this->headers->has('Date')) {
14217  $this->setDate(new \DateTime(null, new \DateTimeZone('UTC')));
14218  }
14219  }
14220  public static function create($content = '', $status = 200, $headers = array())
14221  {
14222  return new static($content, $status, $headers);
14223  }
14224  public function __toString()
14225  {
14226  return sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText) . '
14227 ' . $this->headers . '
14228 ' . $this->getContent();
14229  }
14230  public function __clone()
14231  {
14232  $this->headers = clone $this->headers;
14233  }
14234  public function prepare(Request $request)
14235  {
14236  $headers = $this->headers;
14237  if ($this->isInformational() || $this->isEmpty()) {
14238  $this->setContent(null);
14239  $headers->remove('Content-Type');
14240  $headers->remove('Content-Length');
14241  } else {
14242  if (!$headers->has('Content-Type')) {
14243  $format = $request->getRequestFormat();
14244  if (null !== $format && ($mimeType = $request->getMimeType($format))) {
14245  $headers->set('Content-Type', $mimeType);
14246  }
14247  }
14248  $charset = $this->charset ?: 'UTF-8';
14249  if (!$headers->has('Content-Type')) {
14250  $headers->set('Content-Type', 'text/html; charset=' . $charset);
14251  } elseif (0 === stripos($headers->get('Content-Type'), 'text/') && false === stripos($headers->get('Content-Type'), 'charset')) {
14252  $headers->set('Content-Type', $headers->get('Content-Type') . '; charset=' . $charset);
14253  }
14254  if ($headers->has('Transfer-Encoding')) {
14255  $headers->remove('Content-Length');
14256  }
14257  if ($request->isMethod('HEAD')) {
14258  $length = $headers->get('Content-Length');
14259  $this->setContent(null);
14260  if ($length) {
14261  $headers->set('Content-Length', $length);
14262  }
14263  }
14264  }
14265  if ('HTTP/1.0' != $request->server->get('SERVER_PROTOCOL')) {
14266  $this->setProtocolVersion('1.1');
14267  }
14268  if ('1.0' == $this->getProtocolVersion() && 'no-cache' == $this->headers->get('Cache-Control')) {
14269  $this->headers->set('pragma', 'no-cache');
14270  $this->headers->set('expires', -1);
14271  }
14272  $this->ensureIEOverSSLCompatibility($request);
14273  return $this;
14274  }
14275  public function sendHeaders()
14276  {
14277  if (headers_sent()) {
14278  return $this;
14279  }
14280  header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText), true, $this->statusCode);
14281  foreach ($this->headers->allPreserveCase() as $name => $values) {
14282  foreach ($values as $value) {
14283  header($name . ': ' . $value, false, $this->statusCode);
14284  }
14285  }
14286  foreach ($this->headers->getCookies() as $cookie) {
14287  setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
14288  }
14289  return $this;
14290  }
14291  public function sendContent()
14292  {
14293  echo $this->content;
14294  return $this;
14295  }
14296  public function send()
14297  {
14298  $this->sendHeaders();
14299  $this->sendContent();
14300  if (function_exists('fastcgi_finish_request')) {
14301  fastcgi_finish_request();
14302  } elseif ('cli' !== PHP_SAPI) {
14303  static::closeOutputBuffers(0, true);
14304  }
14305  return $this;
14306  }
14307  public function setContent($content)
14308  {
14309  if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable(array($content, '__toString'))) {
14310  throw new \UnexpectedValueException(sprintf('The Response content must be a string or object implementing __toString(), "%s" given.', gettype($content)));
14311  }
14312  $this->content = (string) $content;
14313  return $this;
14314  }
14315  public function getContent()
14316  {
14317  return $this->content;
14318  }
14319  public function setProtocolVersion($version)
14320  {
14321  $this->version = $version;
14322  return $this;
14323  }
14324  public function getProtocolVersion()
14325  {
14326  return $this->version;
14327  }
14328  public function setStatusCode($code, $text = null)
14329  {
14330  $this->statusCode = $code = (int) $code;
14331  if ($this->isInvalid()) {
14332  throw new \InvalidArgumentException(sprintf('The HTTP status code "%s" is not valid.', $code));
14333  }
14334  if (null === $text) {
14335  $this->statusText = isset(self::$statusTexts[$code]) ? self::$statusTexts[$code] : '';
14336  return $this;
14337  }
14338  if (false === $text) {
14339  $this->statusText = '';
14340  return $this;
14341  }
14342  $this->statusText = $text;
14343  return $this;
14344  }
14345  public function getStatusCode()
14346  {
14347  return $this->statusCode;
14348  }
14349  public function setCharset($charset)
14350  {
14351  $this->charset = $charset;
14352  return $this;
14353  }
14354  public function getCharset()
14355  {
14356  return $this->charset;
14357  }
14358  public function isCacheable()
14359  {
14360  if (!in_array($this->statusCode, array(200, 203, 300, 301, 302, 404, 410))) {
14361  return false;
14362  }
14363  if ($this->headers->hasCacheControlDirective('no-store') || $this->headers->getCacheControlDirective('private')) {
14364  return false;
14365  }
14366  return $this->isValidateable() || $this->isFresh();
14367  }
14368  public function isFresh()
14369  {
14370  return $this->getTtl() > 0;
14371  }
14372  public function isValidateable()
14373  {
14374  return $this->headers->has('Last-Modified') || $this->headers->has('ETag');
14375  }
14376  public function setPrivate()
14377  {
14378  $this->headers->removeCacheControlDirective('public');
14379  $this->headers->addCacheControlDirective('private');
14380  return $this;
14381  }
14382  public function setPublic()
14383  {
14384  $this->headers->addCacheControlDirective('public');
14385  $this->headers->removeCacheControlDirective('private');
14386  return $this;
14387  }
14388  public function mustRevalidate()
14389  {
14390  return $this->headers->hasCacheControlDirective('must-revalidate') || $this->headers->has('proxy-revalidate');
14391  }
14392  public function getDate()
14393  {
14394  return $this->headers->getDate('Date', new \DateTime());
14395  }
14396  public function setDate(\DateTime $date)
14397  {
14398  $date->setTimezone(new \DateTimeZone('UTC'));
14399  $this->headers->set('Date', $date->format('D, d M Y H:i:s') . ' GMT');
14400  return $this;
14401  }
14402  public function getAge()
14403  {
14404  if (null !== ($age = $this->headers->get('Age'))) {
14405  return (int) $age;
14406  }
14407  return max(time() - $this->getDate()->format('U'), 0);
14408  }
14409  public function expire()
14410  {
14411  if ($this->isFresh()) {
14412  $this->headers->set('Age', $this->getMaxAge());
14413  }
14414  return $this;
14415  }
14416  public function getExpires()
14417  {
14418  try {
14419  return $this->headers->getDate('Expires');
14420  } catch (\RuntimeException $e) {
14421  return \DateTime::createFromFormat(DATE_RFC2822, 'Sat, 01 Jan 00 00:00:00 +0000');
14422  }
14423  }
14424  public function setExpires(\DateTime $date = null)
14425  {
14426  if (null === $date) {
14427  $this->headers->remove('Expires');
14428  } else {
14429  $date = clone $date;
14430  $date->setTimezone(new \DateTimeZone('UTC'));
14431  $this->headers->set('Expires', $date->format('D, d M Y H:i:s') . ' GMT');
14432  }
14433  return $this;
14434  }
14435  public function getMaxAge()
14436  {
14437  if ($this->headers->hasCacheControlDirective('s-maxage')) {
14438  return (int) $this->headers->getCacheControlDirective('s-maxage');
14439  }
14440  if ($this->headers->hasCacheControlDirective('max-age')) {
14441  return (int) $this->headers->getCacheControlDirective('max-age');
14442  }
14443  if (null !== $this->getExpires()) {
14444  return $this->getExpires()->format('U') - $this->getDate()->format('U');
14445  }
14446  }
14447  public function setMaxAge($value)
14448  {
14449  $this->headers->addCacheControlDirective('max-age', $value);
14450  return $this;
14451  }
14452  public function setSharedMaxAge($value)
14453  {
14454  $this->setPublic();
14455  $this->headers->addCacheControlDirective('s-maxage', $value);
14456  return $this;
14457  }
14458  public function getTtl()
14459  {
14460  if (null !== ($maxAge = $this->getMaxAge())) {
14461  return $maxAge - $this->getAge();
14462  }
14463  }
14464  public function setTtl($seconds)
14465  {
14466  $this->setSharedMaxAge($this->getAge() + $seconds);
14467  return $this;
14468  }
14469  public function setClientTtl($seconds)
14470  {
14471  $this->setMaxAge($this->getAge() + $seconds);
14472  return $this;
14473  }
14474  public function getLastModified()
14475  {
14476  return $this->headers->getDate('Last-Modified');
14477  }
14478  public function setLastModified(\DateTime $date = null)
14479  {
14480  if (null === $date) {
14481  $this->headers->remove('Last-Modified');
14482  } else {
14483  $date = clone $date;
14484  $date->setTimezone(new \DateTimeZone('UTC'));
14485  $this->headers->set('Last-Modified', $date->format('D, d M Y H:i:s') . ' GMT');
14486  }
14487  return $this;
14488  }
14489  public function getEtag()
14490  {
14491  return $this->headers->get('ETag');
14492  }
14493  public function setEtag($etag = null, $weak = false)
14494  {
14495  if (null === $etag) {
14496  $this->headers->remove('Etag');
14497  } else {
14498  if (0 !== strpos($etag, '"')) {
14499  $etag = '"' . $etag . '"';
14500  }
14501  $this->headers->set('ETag', (true === $weak ? 'W/' : '') . $etag);
14502  }
14503  return $this;
14504  }
14505  public function setCache(array $options)
14506  {
14507  if ($diff = array_diff(array_keys($options), array('etag', 'last_modified', 'max_age', 's_maxage', 'private', 'public'))) {
14508  throw new \InvalidArgumentException(sprintf('Response does not support the following options: "%s".', implode('", "', array_values($diff))));
14509  }
14510  if (isset($options['etag'])) {
14511  $this->setEtag($options['etag']);
14512  }
14513  if (isset($options['last_modified'])) {
14514  $this->setLastModified($options['last_modified']);
14515  }
14516  if (isset($options['max_age'])) {
14517  $this->setMaxAge($options['max_age']);
14518  }
14519  if (isset($options['s_maxage'])) {
14520  $this->setSharedMaxAge($options['s_maxage']);
14521  }
14522  if (isset($options['public'])) {
14523  if ($options['public']) {
14524  $this->setPublic();
14525  } else {
14526  $this->setPrivate();
14527  }
14528  }
14529  if (isset($options['private'])) {
14530  if ($options['private']) {
14531  $this->setPrivate();
14532  } else {
14533  $this->setPublic();
14534  }
14535  }
14536  return $this;
14537  }
14538  public function setNotModified()
14539  {
14540  $this->setStatusCode(304);
14541  $this->setContent(null);
14542  foreach (array('Allow', 'Content-Encoding', 'Content-Language', 'Content-Length', 'Content-MD5', 'Content-Type', 'Last-Modified') as $header) {
14543  $this->headers->remove($header);
14544  }
14545  return $this;
14546  }
14547  public function hasVary()
14548  {
14549  return null !== $this->headers->get('Vary');
14550  }
14551  public function getVary()
14552  {
14553  if (!($vary = $this->headers->get('Vary', null, false))) {
14554  return array();
14555  }
14556  $ret = array();
14557  foreach ($vary as $item) {
14558  $ret = array_merge($ret, preg_split('/[\\s,]+/', $item));
14559  }
14560  return $ret;
14561  }
14562  public function setVary($headers, $replace = true)
14563  {
14564  $this->headers->set('Vary', $headers, $replace);
14565  return $this;
14566  }
14567  public function isNotModified(Request $request)
14568  {
14569  if (!$request->isMethodSafe()) {
14570  return false;
14571  }
14572  $notModified = false;
14573  $lastModified = $this->headers->get('Last-Modified');
14574  $modifiedSince = $request->headers->get('If-Modified-Since');
14575  if ($etags = $request->getEtags()) {
14576  $notModified = in_array($this->getEtag(), $etags) || in_array('*', $etags);
14577  }
14578  if ($modifiedSince && $lastModified) {
14579  $notModified = strtotime($modifiedSince) >= strtotime($lastModified) && (!$etags || $notModified);
14580  }
14581  if ($notModified) {
14582  $this->setNotModified();
14583  }
14584  return $notModified;
14585  }
14586  public function isInvalid()
14587  {
14588  return $this->statusCode < 100 || $this->statusCode >= 600;
14589  }
14590  public function isInformational()
14591  {
14592  return $this->statusCode >= 100 && $this->statusCode < 200;
14593  }
14594  public function isSuccessful()
14595  {
14596  return $this->statusCode >= 200 && $this->statusCode < 300;
14597  }
14598  public function isRedirection()
14599  {
14600  return $this->statusCode >= 300 && $this->statusCode < 400;
14601  }
14602  public function isClientError()
14603  {
14604  return $this->statusCode >= 400 && $this->statusCode < 500;
14605  }
14606  public function isServerError()
14607  {
14608  return $this->statusCode >= 500 && $this->statusCode < 600;
14609  }
14610  public function isOk()
14611  {
14612  return 200 === $this->statusCode;
14613  }
14614  public function isForbidden()
14615  {
14616  return 403 === $this->statusCode;
14617  }
14618  public function isNotFound()
14619  {
14620  return 404 === $this->statusCode;
14621  }
14622  public function isRedirect($location = null)
14623  {
14624  return in_array($this->statusCode, array(201, 301, 302, 303, 307, 308)) && (null === $location ?: $location == $this->headers->get('Location'));
14625  }
14626  public function isEmpty()
14627  {
14628  return in_array($this->statusCode, array(204, 304));
14629  }
14630  public static function closeOutputBuffers($targetLevel, $flush)
14631  {
14632  $status = ob_get_status(true);
14633  $level = count($status);
14634  while ($level-- > $targetLevel && (!empty($status[$level]['del']) || isset($status[$level]['flags']) && $status[$level]['flags'] & PHP_OUTPUT_HANDLER_REMOVABLE && $status[$level]['flags'] & ($flush ? PHP_OUTPUT_HANDLER_FLUSHABLE : PHP_OUTPUT_HANDLER_CLEANABLE))) {
14635  if ($flush) {
14636  ob_end_flush();
14637  } else {
14638  ob_end_clean();
14639  }
14640  }
14641  }
14642  protected function ensureIEOverSSLCompatibility(Request $request)
14643  {
14644  if (false !== stripos($this->headers->get('Content-Disposition'), 'attachment') && preg_match('/MSIE (.*?);/i', $request->server->get('HTTP_USER_AGENT'), $match) == 1 && true === $request->isSecure()) {
14645  if ((int) preg_replace('/(MSIE )(.*?);/', '$2', $match[0]) < 9) {
14646  $this->headers->remove('Cache-Control');
14647  }
14648  }
14649  }
14650 }
14651 namespace Illuminate\Http;
14652 
14654 trait ResponseTrait
14656  public function header($key, $value, $replace = true)
14657  {
14658  $this->headers->set($key, $value, $replace);
14659  return $this;
14660  }
14661  public function withCookie(Cookie $cookie)
14662  {
14663  $this->headers->setCookie($cookie);
14664  return $this;
14665  }
14666 }
14667 namespace Illuminate\Http;
14668 
14669 use ArrayObject;
14673 class Response extends BaseResponse
14674 {
14675  use ResponseTrait;
14676  public $original;
14677  public function setContent($content)
14678  {
14679  $this->original = $content;
14680  if ($this->shouldBeJson($content)) {
14681  $this->headers->set('Content-Type', 'application/json');
14682  $content = $this->morphToJson($content);
14683  } elseif ($content instanceof Renderable) {
14684  $content = $content->render();
14685  }
14686  return parent::setContent($content);
14687  }
14688  protected function morphToJson($content)
14689  {
14690  if ($content instanceof Jsonable) {
14691  return $content->toJson();
14692  }
14693  return json_encode($content);
14694  }
14695  protected function shouldBeJson($content)
14696  {
14697  return $content instanceof Jsonable || $content instanceof ArrayObject || is_array($content);
14698  }
14699  public function getOriginalContent()
14700  {
14701  return $this->original;
14702  }
14703 }
14705 
14707 {
14708  const COOKIES_FLAT = 'flat';
14709  const COOKIES_ARRAY = 'array';
14710  const DISPOSITION_ATTACHMENT = 'attachment';
14711  const DISPOSITION_INLINE = 'inline';
14712  protected $computedCacheControl = array();
14713  protected $cookies = array();
14714  protected $headerNames = array();
14715  public function __construct(array $headers = array())
14716  {
14717  parent::__construct($headers);
14718  if (!isset($this->headers['cache-control'])) {
14719  $this->set('Cache-Control', '');
14720  }
14721  }
14722  public function __toString()
14723  {
14724  $cookies = '';
14725  foreach ($this->getCookies() as $cookie) {
14726  $cookies .= 'Set-Cookie: ' . $cookie . '
14727 ';
14728  }
14729  ksort($this->headerNames);
14730  return parent::__toString() . $cookies;
14731  }
14732  public function allPreserveCase()
14733  {
14734  return array_combine($this->headerNames, $this->headers);
14735  }
14736  public function replace(array $headers = array())
14737  {
14738  $this->headerNames = array();
14739  parent::replace($headers);
14740  if (!isset($this->headers['cache-control'])) {
14741  $this->set('Cache-Control', '');
14742  }
14743  }
14744  public function set($key, $values, $replace = true)
14745  {
14746  parent::set($key, $values, $replace);
14747  $uniqueKey = strtr(strtolower($key), '_', '-');
14748  $this->headerNames[$uniqueKey] = $key;
14749  if (in_array($uniqueKey, array('cache-control', 'etag', 'last-modified', 'expires'))) {
14750  $computed = $this->computeCacheControlValue();
14751  $this->headers['cache-control'] = array($computed);
14752  $this->headerNames['cache-control'] = 'Cache-Control';
14753  $this->computedCacheControl = $this->parseCacheControl($computed);
14754  }
14755  }
14756  public function remove($key)
14757  {
14758  parent::remove($key);
14759  $uniqueKey = strtr(strtolower($key), '_', '-');
14760  unset($this->headerNames[$uniqueKey]);
14761  if ('cache-control' === $uniqueKey) {
14762  $this->computedCacheControl = array();
14763  }
14764  }
14765  public function hasCacheControlDirective($key)
14766  {
14767  return array_key_exists($key, $this->computedCacheControl);
14768  }
14769  public function getCacheControlDirective($key)
14770  {
14771  return array_key_exists($key, $this->computedCacheControl) ? $this->computedCacheControl[$key] : null;
14772  }
14773  public function setCookie(Cookie $cookie)
14774  {
14775  $this->cookies[$cookie->getDomain()][$cookie->getPath()][$cookie->getName()] = $cookie;
14776  }
14777  public function removeCookie($name, $path = '/', $domain = null)
14778  {
14779  if (null === $path) {
14780  $path = '/';
14781  }
14782  unset($this->cookies[$domain][$path][$name]);
14783  if (empty($this->cookies[$domain][$path])) {
14784  unset($this->cookies[$domain][$path]);
14785  if (empty($this->cookies[$domain])) {
14786  unset($this->cookies[$domain]);
14787  }
14788  }
14789  }
14790  public function getCookies($format = self::COOKIES_FLAT)
14791  {
14792  if (!in_array($format, array(self::COOKIES_FLAT, self::COOKIES_ARRAY))) {
14793  throw new \InvalidArgumentException(sprintf('Format "%s" invalid (%s).', $format, implode(', ', array(self::COOKIES_FLAT, self::COOKIES_ARRAY))));
14794  }
14795  if (self::COOKIES_ARRAY === $format) {
14796  return $this->cookies;
14797  }
14798  $flattenedCookies = array();
14799  foreach ($this->cookies as $path) {
14800  foreach ($path as $cookies) {
14801  foreach ($cookies as $cookie) {
14802  $flattenedCookies[] = $cookie;
14803  }
14804  }
14805  }
14806  return $flattenedCookies;
14807  }
14808  public function clearCookie($name, $path = '/', $domain = null, $secure = false, $httpOnly = true)
14809  {
14810  $this->setCookie(new Cookie($name, null, 1, $path, $domain, $secure, $httpOnly));
14811  }
14812  public function makeDisposition($disposition, $filename, $filenameFallback = '')
14813  {
14814  if (!in_array($disposition, array(self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE))) {
14815  throw new \InvalidArgumentException(sprintf('The disposition must be either "%s" or "%s".', self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE));
14816  }
14817  if ('' == $filenameFallback) {
14818  $filenameFallback = $filename;
14819  }
14820  if (!preg_match('/^[\\x20-\\x7e]*$/', $filenameFallback)) {
14821  throw new \InvalidArgumentException('The filename fallback must only contain ASCII characters.');
14822  }
14823  if (false !== strpos($filenameFallback, '%')) {
14824  throw new \InvalidArgumentException('The filename fallback cannot contain the "%" character.');
14825  }
14826  if (false !== strpos($filename, '/') || false !== strpos($filename, '\\') || false !== strpos($filenameFallback, '/') || false !== strpos($filenameFallback, '\\')) {
14827  throw new \InvalidArgumentException('The filename and the fallback cannot contain the "/" and "\\" characters.');
14828  }
14829  $output = sprintf('%s; filename="%s"', $disposition, str_replace('"', '\\"', $filenameFallback));
14830  if ($filename !== $filenameFallback) {
14831  $output .= sprintf('; filename*=utf-8\'\'%s', rawurlencode($filename));
14832  }
14833  return $output;
14834  }
14835  protected function computeCacheControlValue()
14836  {
14837  if (!$this->cacheControl && !$this->has('ETag') && !$this->has('Last-Modified') && !$this->has('Expires')) {
14838  return 'no-cache';
14839  }
14840  if (!$this->cacheControl) {
14841  return 'private, must-revalidate';
14842  }
14843  $header = $this->getCacheControlHeader();
14844  if (isset($this->cacheControl['public']) || isset($this->cacheControl['private'])) {
14845  return $header;
14846  }
14847  if (!isset($this->cacheControl['s-maxage'])) {
14848  return $header . ', private';
14849  }
14850  return $header;
14851  }
14852 }
14854 
14855 class Cookie
14856 {
14857  protected $name;
14858  protected $value;
14859  protected $domain;
14860  protected $expire;
14861  protected $path;
14862  protected $secure;
14863  protected $httpOnly;
14864  public function __construct($name, $value = null, $expire = 0, $path = '/', $domain = null, $secure = false, $httpOnly = true)
14865  {
14866  if (preg_match('/[=,;
14867  ]/', $name)) {
14868  throw new \InvalidArgumentException(sprintf('The cookie name "%s" contains invalid characters.', $name));
14869  }
14870  if (empty($name)) {
14871  throw new \InvalidArgumentException('The cookie name cannot be empty.');
14872  }
14873  if ($expire instanceof \DateTime) {
14874  $expire = $expire->format('U');
14875  } elseif (!is_numeric($expire)) {
14876  $expire = strtotime($expire);
14877  if (false === $expire || -1 === $expire) {
14878  throw new \InvalidArgumentException('The cookie expiration time is not valid.');
14879  }
14880  }
14881  $this->name = $name;
14882  $this->value = $value;
14883  $this->domain = $domain;
14884  $this->expire = $expire;
14885  $this->path = empty($path) ? '/' : $path;
14886  $this->secure = (bool) $secure;
14887  $this->httpOnly = (bool) $httpOnly;
14888  }
14889  public function __toString()
14890  {
14891  $str = urlencode($this->getName()) . '=';
14892  if ('' === (string) $this->getValue()) {
14893  $str .= 'deleted; expires=' . gmdate('D, d-M-Y H:i:s T', time() - 31536001);
14894  } else {
14895  $str .= urlencode($this->getValue());
14896  if ($this->getExpiresTime() !== 0) {
14897  $str .= '; expires=' . gmdate('D, d-M-Y H:i:s T', $this->getExpiresTime());
14898  }
14899  }
14900  if ($this->path) {
14901  $str .= '; path=' . $this->path;
14902  }
14903  if ($this->getDomain()) {
14904  $str .= '; domain=' . $this->getDomain();
14905  }
14906  if (true === $this->isSecure()) {
14907  $str .= '; secure';
14908  }
14909  if (true === $this->isHttpOnly()) {
14910  $str .= '; httponly';
14911  }
14912  return $str;
14913  }
14914  public function getName()
14915  {
14916  return $this->name;
14917  }
14918  public function getValue()
14919  {
14920  return $this->value;
14921  }
14922  public function getDomain()
14923  {
14924  return $this->domain;
14925  }
14926  public function getExpiresTime()
14927  {
14928  return $this->expire;
14929  }
14930  public function getPath()
14931  {
14932  return $this->path;
14933  }
14934  public function isSecure()
14935  {
14936  return $this->secure;
14937  }
14938  public function isHttpOnly()
14939  {
14940  return $this->httpOnly;
14941  }
14942  public function isCleared()
14943  {
14944  return $this->expire < time();
14945  }
14946 }
14948 
14950 {
14951  private function __construct()
14952  {
14953  }
14954  public static function equals($knownString, $userInput)
14955  {
14956  if (!is_string($knownString)) {
14957  $knownString = (string) $knownString;
14958  }
14959  if (!is_string($userInput)) {
14960  $userInput = (string) $userInput;
14961  }
14962  if (function_exists('hash_equals')) {
14963  return hash_equals($knownString, $userInput);
14964  }
14965  $knownLen = self::safeStrlen($knownString);
14966  $userLen = self::safeStrlen($userInput);
14967  if ($userLen !== $knownLen) {
14968  return false;
14969  }
14970  $result = 0;
14971  for ($i = 0; $i < $knownLen; $i++) {
14972  $result |= ord($knownString[$i]) ^ ord($userInput[$i]);
14973  }
14974  return 0 === $result;
14975  }
14976  public static function safeStrlen($string)
14977  {
14978  static $funcExists = null;
14979  if (null === $funcExists) {
14980  $funcExists = function_exists('mb_strlen');
14981  }
14982  if ($funcExists) {
14983  return mb_strlen($string, '8bit');
14984  }
14985  return strlen($string);
14986  }
14987 }
14989 
14991 {
14992  public function nextBytes($nbBytes);
14993 }
14995 
14997 final class SecureRandom implements SecureRandomInterface
14998 {
14999  private $logger;
15000  private $useOpenSsl;
15001  private $seed;
15002  private $seedUpdated;
15003  private $seedLastUpdatedAt;
15004  private $seedFile;
15005  public function __construct($seedFile = null, LoggerInterface $logger = null)
15006  {
15007  $this->seedFile = $seedFile;
15008  $this->logger = $logger;
15009  if ('\\' === DIRECTORY_SEPARATOR && PHP_VERSION_ID < 50304) {
15010  $this->useOpenSsl = false;
15011  } elseif (!function_exists('openssl_random_pseudo_bytes')) {
15012  if (null !== $this->logger) {
15013  $this->logger->notice('It is recommended that you enable the "openssl" extension for random number generation.');
15014  }
15015  $this->useOpenSsl = false;
15016  } else {
15017  $this->useOpenSsl = true;
15018  }
15019  }
15020  public function nextBytes($nbBytes)
15021  {
15022  if ($this->useOpenSsl) {
15023  $bytes = openssl_random_pseudo_bytes($nbBytes, $strong);
15024  if (false !== $bytes && true === $strong) {
15025  return $bytes;
15026  }
15027  if (null !== $this->logger) {
15028  $this->logger->info('OpenSSL did not produce a secure random number.');
15029  }
15030  }
15031  if (null === $this->seed) {
15032  if (null === $this->seedFile) {
15033  throw new \RuntimeException('You need to specify a file path to store the seed.');
15034  }
15035  if (is_file($this->seedFile)) {
15036  list($this->seed, $this->seedLastUpdatedAt) = $this->readSeed();
15037  } else {
15038  $this->seed = uniqid(mt_rand(), true);
15039  $this->updateSeed();
15040  }
15041  }
15042  $bytes = '';
15043  while (strlen($bytes) < $nbBytes) {
15044  static $incr = 1;
15045  $bytes .= hash('sha512', $incr++ . $this->seed . uniqid(mt_rand(), true) . $nbBytes, true);
15046  $this->seed = base64_encode(hash('sha512', $this->seed . $bytes . $nbBytes, true));
15047  $this->updateSeed();
15048  }
15049  return substr($bytes, 0, $nbBytes);
15050  }
15051  private function readSeed()
15052  {
15053  return json_decode(file_get_contents($this->seedFile));
15054  }
15055  private function updateSeed()
15056  {
15057  if (!$this->seedUpdated && $this->seedLastUpdatedAt < time() - mt_rand(1, 10)) {
15058  file_put_contents($this->seedFile, json_encode(array($this->seed, microtime(true))));
15059  }
15060  $this->seedUpdated = true;
15061  }
15062 }
15064 
15065 class SplFileInfo extends \SplFileInfo
15066 {
15067  private $relativePath;
15068  private $relativePathname;
15069  public function __construct($file, $relativePath, $relativePathname)
15070  {
15071  parent::__construct($file);
15072  $this->relativePath = $relativePath;
15073  $this->relativePathname = $relativePathname;
15074  }
15075  public function getRelativePath()
15076  {
15077  return $this->relativePath;
15078  }
15079  public function getRelativePathname()
15080  {
15081  return $this->relativePathname;
15082  }
15083  public function getContents()
15084  {
15085  $level = error_reporting(0);
15086  $content = file_get_contents($this->getPathname());
15087  error_reporting($level);
15088  if (false === $content) {
15089  $error = error_get_last();
15090  throw new \RuntimeException($error['message']);
15091  }
15092  return $content;
15093  }
15094 }
15096 
15097 class Regex implements ValueInterface
15098 {
15099  const START_FLAG = '^';
15100  const END_FLAG = '$';
15101  const BOUNDARY = '~';
15102  const JOKER = '.*';
15103  const ESCAPING = '\\';
15104  private $pattern;
15105  private $options;
15106  private $startFlag;
15107  private $endFlag;
15108  private $startJoker;
15109  private $endJoker;
15110  public static function create($expr)
15111  {
15112  if (preg_match('/^(.{3,}?)([imsxuADU]*)$/', $expr, $m)) {
15113  $start = substr($m[1], 0, 1);
15114  $end = substr($m[1], -1);
15115  if ($start === $end && !preg_match('/[*?[:alnum:] \\\\]/', $start) || $start === '{' && $end === '}' || $start === '(' && $end === ')') {
15116  return new self(substr($m[1], 1, -1), $m[2], $end);
15117  }
15118  }
15119  throw new \InvalidArgumentException('Given expression is not a regex.');
15120  }
15121  public function __construct($pattern, $options = '', $delimiter = null)
15122  {
15123  if (null !== $delimiter) {
15124  $pattern = str_replace('\\' . $delimiter, $delimiter, $pattern);
15125  }
15126  $this->parsePattern($pattern);
15127  $this->options = $options;
15128  }
15129  public function __toString()
15130  {
15131  return $this->render();
15132  }
15133  public function render()
15134  {
15135  return self::BOUNDARY . $this->renderPattern() . self::BOUNDARY . $this->options;
15136  }
15137  public function renderPattern()
15138  {
15139  return ($this->startFlag ? self::START_FLAG : '') . ($this->startJoker ? self::JOKER : '') . str_replace(self::BOUNDARY, '\\' . self::BOUNDARY, $this->pattern) . ($this->endJoker ? self::JOKER : '') . ($this->endFlag ? self::END_FLAG : '');
15140  }
15141  public function isCaseSensitive()
15142  {
15143  return !$this->hasOption('i');
15144  }
15145  public function getType()
15146  {
15147  return Expression::TYPE_REGEX;
15148  }
15149  public function prepend($expr)
15150  {
15151  $this->pattern = $expr . $this->pattern;
15152  return $this;
15153  }
15154  public function append($expr)
15155  {
15156  $this->pattern .= $expr;
15157  return $this;
15158  }
15159  public function hasOption($option)
15160  {
15161  return false !== strpos($this->options, $option);
15162  }
15163  public function addOption($option)
15164  {
15165  if (!$this->hasOption($option)) {
15166  $this->options .= $option;
15167  }
15168  return $this;
15169  }
15170  public function removeOption($option)
15171  {
15172  $this->options = str_replace($option, '', $this->options);
15173  return $this;
15174  }
15175  public function setStartFlag($startFlag)
15176  {
15177  $this->startFlag = $startFlag;
15178  return $this;
15179  }
15180  public function hasStartFlag()
15181  {
15182  return $this->startFlag;
15183  }
15184  public function setEndFlag($endFlag)
15185  {
15186  $this->endFlag = (bool) $endFlag;
15187  return $this;
15188  }
15189  public function hasEndFlag()
15190  {
15191  return $this->endFlag;
15192  }
15193  public function setStartJoker($startJoker)
15194  {
15195  $this->startJoker = $startJoker;
15196  return $this;
15197  }
15198  public function hasStartJoker()
15199  {
15200  return $this->startJoker;
15201  }
15202  public function setEndJoker($endJoker)
15203  {
15204  $this->endJoker = (bool) $endJoker;
15205  return $this;
15206  }
15207  public function hasEndJoker()
15208  {
15209  return $this->endJoker;
15210  }
15211  public function replaceJokers($replacement)
15212  {
15213  $replace = function ($subject) use($replacement) {
15214  $subject = $subject[0];
15215  $replace = 0 === substr_count($subject, '\\') % 2;
15216  return $replace ? str_replace('.', $replacement, $subject) : $subject;
15217  };
15218  $this->pattern = preg_replace_callback('~[\\\\]*\\.~', $replace, $this->pattern);
15219  return $this;
15220  }
15221  private function parsePattern($pattern)
15222  {
15223  if ($this->startFlag = self::START_FLAG === substr($pattern, 0, 1)) {
15224  $pattern = substr($pattern, 1);
15225  }
15226  if ($this->startJoker = self::JOKER === substr($pattern, 0, 2)) {
15227  $pattern = substr($pattern, 2);
15228  }
15229  if ($this->endFlag = self::END_FLAG === substr($pattern, -1) && self::ESCAPING !== substr($pattern, -2, -1)) {
15230  $pattern = substr($pattern, 0, -1);
15231  }
15232  if ($this->endJoker = self::JOKER === substr($pattern, -2) && self::ESCAPING !== substr($pattern, -3, -2)) {
15233  $pattern = substr($pattern, 0, -2);
15234  }
15235  $this->pattern = $pattern;
15236  }
15237 }
15239 
15241 {
15242  public function render();
15243  public function renderPattern();
15244  public function isCaseSensitive();
15245  public function getType();
15246  public function prepend($expr);
15247  public function append($expr);
15248 }
15250 
15251 class Expression implements ValueInterface
15252 {
15253  const TYPE_REGEX = 1;
15254  const TYPE_GLOB = 2;
15255  private $value;
15256  public static function create($expr)
15257  {
15258  return new self($expr);
15259  }
15260  public function __construct($expr)
15261  {
15262  try {
15263  $this->value = Regex::create($expr);
15264  } catch (\InvalidArgumentException $e) {
15265  $this->value = new Glob($expr);
15266  }
15267  }
15268  public function __toString()
15269  {
15270  return $this->render();
15271  }
15272  public function render()
15273  {
15274  return $this->value->render();
15275  }
15276  public function renderPattern()
15277  {
15278  return $this->value->renderPattern();
15279  }
15280  public function isCaseSensitive()
15281  {
15282  return $this->value->isCaseSensitive();
15283  }
15284  public function getType()
15285  {
15286  return $this->value->getType();
15287  }
15288  public function prepend($expr)
15289  {
15290  $this->value->prepend($expr);
15291  return $this;
15292  }
15293  public function append($expr)
15294  {
15295  $this->value->append($expr);
15296  return $this;
15297  }
15298  public function isRegex()
15299  {
15300  return self::TYPE_REGEX === $this->value->getType();
15301  }
15302  public function isGlob()
15303  {
15304  return self::TYPE_GLOB === $this->value->getType();
15305  }
15306  public function getGlob()
15307  {
15308  if (self::TYPE_GLOB !== $this->value->getType()) {
15309  throw new \LogicException('Regex can\'t be transformed to glob.');
15310  }
15311  return $this->value;
15312  }
15313  public function getRegex()
15314  {
15315  return self::TYPE_REGEX === $this->value->getType() ? $this->value : $this->value->toRegex();
15316  }
15317 }
15319 
15320 abstract class FilterIterator extends \FilterIterator
15321 {
15322  public function rewind()
15323  {
15324  $iterator = $this;
15325  while ($iterator instanceof \OuterIterator) {
15326  $innerIterator = $iterator->getInnerIterator();
15327  if ($innerIterator instanceof RecursiveDirectoryIterator) {
15328  if ($innerIterator->isRewindable()) {
15329  $innerIterator->next();
15330  $innerIterator->rewind();
15331  }
15332  } elseif ($iterator->getInnerIterator() instanceof \FilesystemIterator) {
15333  $iterator->getInnerIterator()->next();
15334  $iterator->getInnerIterator()->rewind();
15335  }
15336  $iterator = $iterator->getInnerIterator();
15337  }
15338  parent::rewind();
15339  }
15340 }
15342 
15345 {
15346  protected $matchRegexps = array();
15347  protected $noMatchRegexps = array();
15348  public function __construct(\Iterator $iterator, array $matchPatterns, array $noMatchPatterns)
15349  {
15350  foreach ($matchPatterns as $pattern) {
15351  $this->matchRegexps[] = $this->toRegex($pattern);
15352  }
15353  foreach ($noMatchPatterns as $pattern) {
15354  $this->noMatchRegexps[] = $this->toRegex($pattern);
15355  }
15356  parent::__construct($iterator);
15357  }
15358  protected function isRegex($str)
15359  {
15360  return Expression::create($str)->isRegex();
15361  }
15362  protected abstract function toRegex($str);
15363 }
15365 
15367 {
15368  public function accept()
15369  {
15370  $filename = $this->current()->getRelativePathname();
15371  if ('\\' === DIRECTORY_SEPARATOR) {
15372  $filename = strtr($filename, '\\', '/');
15373  }
15374  foreach ($this->noMatchRegexps as $regex) {
15375  if (preg_match($regex, $filename)) {
15376  return false;
15377  }
15378  }
15379  $match = true;
15380  if ($this->matchRegexps) {
15381  $match = false;
15382  foreach ($this->matchRegexps as $regex) {
15383  if (preg_match($regex, $filename)) {
15384  return true;
15385  }
15386  }
15387  }
15388  return $match;
15389  }
15390  protected function toRegex($str)
15391  {
15392  return $this->isRegex($str) ? $str : '/' . preg_quote($str, '/') . '/';
15393  }
15394 }
15396 
15398 {
15399  private $patterns = array();
15400  public function __construct(\Iterator $iterator, array $directories)
15401  {
15402  foreach ($directories as $directory) {
15403  $this->patterns[] = '#(^|/)' . preg_quote($directory, '#') . '(/|$)#';
15404  }
15405  parent::__construct($iterator);
15406  }
15407  public function accept()
15408  {
15409  $path = $this->isDir() ? $this->current()->getRelativePathname() : $this->current()->getRelativePath();
15410  $path = strtr($path, '\\', '/');
15411  foreach ($this->patterns as $pattern) {
15412  if (preg_match($pattern, $path)) {
15413  return false;
15414  }
15415  }
15416  return true;
15417  }
15418 }
15420 
15424 {
15425  private $ignoreUnreadableDirs;
15426  private $rewindable;
15427  public function __construct($path, $flags, $ignoreUnreadableDirs = false)
15428  {
15429  if ($flags & (self::CURRENT_AS_PATHNAME | self::CURRENT_AS_SELF)) {
15430  throw new \RuntimeException('This iterator only support returning current as fileinfo.');
15431  }
15432  parent::__construct($path, $flags);
15433  $this->ignoreUnreadableDirs = $ignoreUnreadableDirs;
15434  }
15435  public function current()
15436  {
15437  return new SplFileInfo(parent::current()->getPathname(), $this->getSubPath(), $this->getSubPathname());
15438  }
15439  public function getChildren()
15440  {
15441  try {
15442  $children = parent::getChildren();
15443  if ($children instanceof self) {
15444  $children->ignoreUnreadableDirs = $this->ignoreUnreadableDirs;
15445  }
15446  return $children;
15447  } catch (\UnexpectedValueException $e) {
15448  if ($this->ignoreUnreadableDirs) {
15449  return new \RecursiveArrayIterator(array());
15450  } else {
15451  throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e);
15452  }
15453  }
15454  }
15455  public function rewind()
15456  {
15457  if (false === $this->isRewindable()) {
15458  return;
15459  }
15460  parent::next();
15461  parent::rewind();
15462  }
15463  public function isRewindable()
15464  {
15465  if (null !== $this->rewindable) {
15466  return $this->rewindable;
15467  }
15468  if (false !== ($stream = @opendir($this->getPath()))) {
15469  $infos = stream_get_meta_data($stream);
15470  closedir($stream);
15471  if ($infos['seekable']) {
15472  return $this->rewindable = true;
15473  }
15474  }
15475  return $this->rewindable = false;
15476  }
15477 }
15479 
15481 {
15482  const ONLY_FILES = 1;
15483  const ONLY_DIRECTORIES = 2;
15484  private $mode;
15485  public function __construct(\Iterator $iterator, $mode)
15486  {
15487  $this->mode = $mode;
15488  parent::__construct($iterator);
15489  }
15490  public function accept()
15491  {
15492  $fileinfo = $this->current();
15493  if (self::ONLY_DIRECTORIES === (self::ONLY_DIRECTORIES & $this->mode) && $fileinfo->isFile()) {
15494  return false;
15495  } elseif (self::ONLY_FILES === (self::ONLY_FILES & $this->mode) && $fileinfo->isDir()) {
15496  return false;
15497  }
15498  return true;
15499  }
15500 }
15502 
15503 class Shell
15504 {
15505  const TYPE_UNIX = 1;
15506  const TYPE_DARWIN = 2;
15507  const TYPE_CYGWIN = 3;
15508  const TYPE_WINDOWS = 4;
15509  const TYPE_BSD = 5;
15510  private $type;
15511  public function getType()
15512  {
15513  if (null === $this->type) {
15514  $this->type = $this->guessType();
15515  }
15516  return $this->type;
15517  }
15518  public function testCommand($command)
15519  {
15520  if (!function_exists('exec')) {
15521  return false;
15522  }
15523  $testCommand = 'which ';
15524  if (self::TYPE_WINDOWS === $this->type) {
15525  $testCommand = 'where ';
15526  }
15527  $command = escapeshellcmd($command);
15528  exec($testCommand . $command, $output, $code);
15529  return 0 === $code && count($output) > 0;
15530  }
15531  private function guessType()
15532  {
15533  $os = strtolower(PHP_OS);
15534  if (false !== strpos($os, 'cygwin')) {
15535  return self::TYPE_CYGWIN;
15536  }
15537  if (false !== strpos($os, 'darwin')) {
15538  return self::TYPE_DARWIN;
15539  }
15540  if (false !== strpos($os, 'bsd')) {
15541  return self::TYPE_BSD;
15542  }
15543  if (0 === strpos($os, 'win')) {
15544  return self::TYPE_WINDOWS;
15545  }
15546  return self::TYPE_UNIX;
15547  }
15548 }
15550 
15552 {
15553  public function setFollowLinks($followLinks);
15554  public function setMode($mode);
15555  public function setExclude(array $exclude);
15556  public function setDepths(array $depths);
15557  public function setNames(array $names);
15558  public function setNotNames(array $notNames);
15559  public function setContains(array $contains);
15560  public function setNotContains(array $notContains);
15561  public function setSizes(array $sizes);
15562  public function setDates(array $dates);
15563  public function setFilters(array $filters);
15564  public function setSort($sort);
15565  public function setPath(array $paths);
15566  public function setNotPath(array $notPaths);
15567  public function ignoreUnreadableDirs($ignore = true);
15568  public function searchInDirectory($dir);
15569  public function isSupported();
15570  public function getName();
15571 }
15573 
15574 abstract class AbstractAdapter implements AdapterInterface
15575 {
15576  protected $followLinks = false;
15577  protected $mode = 0;
15578  protected $minDepth = 0;
15579  protected $maxDepth = PHP_INT_MAX;
15580  protected $exclude = array();
15581  protected $names = array();
15582  protected $notNames = array();
15583  protected $contains = array();
15584  protected $notContains = array();
15585  protected $sizes = array();
15586  protected $dates = array();
15587  protected $filters = array();
15588  protected $sort = false;
15589  protected $paths = array();
15590  protected $notPaths = array();
15591  protected $ignoreUnreadableDirs = false;
15592  private static $areSupported = array();
15593  public function isSupported()
15594  {
15595  $name = $this->getName();
15596  if (!array_key_exists($name, self::$areSupported)) {
15597  self::$areSupported[$name] = $this->canBeUsed();
15598  }
15599  return self::$areSupported[$name];
15600  }
15601  public function setFollowLinks($followLinks)
15602  {
15603  $this->followLinks = $followLinks;
15604  return $this;
15605  }
15606  public function setMode($mode)
15607  {
15608  $this->mode = $mode;
15609  return $this;
15610  }
15611  public function setDepths(array $depths)
15612  {
15613  $this->minDepth = 0;
15614  $this->maxDepth = PHP_INT_MAX;
15615  foreach ($depths as $comparator) {
15616  switch ($comparator->getOperator()) {
15617  case '>':
15618  $this->minDepth = $comparator->getTarget() + 1;
15619  break;
15620  case '>=':
15621  $this->minDepth = $comparator->getTarget();
15622  break;
15623  case '<':
15624  $this->maxDepth = $comparator->getTarget() - 1;
15625  break;
15626  case '<=':
15627  $this->maxDepth = $comparator->getTarget();
15628  break;
15629  default:
15630  $this->minDepth = $this->maxDepth = $comparator->getTarget();
15631  }
15632  }
15633  return $this;
15634  }
15635  public function setExclude(array $exclude)
15636  {
15637  $this->exclude = $exclude;
15638  return $this;
15639  }
15640  public function setNames(array $names)
15641  {
15642  $this->names = $names;
15643  return $this;
15644  }
15645  public function setNotNames(array $notNames)
15646  {
15647  $this->notNames = $notNames;
15648  return $this;
15649  }
15650  public function setContains(array $contains)
15651  {
15652  $this->contains = $contains;
15653  return $this;
15654  }
15655  public function setNotContains(array $notContains)
15656  {
15657  $this->notContains = $notContains;
15658  return $this;
15659  }
15660  public function setSizes(array $sizes)
15661  {
15662  $this->sizes = $sizes;
15663  return $this;
15664  }
15665  public function setDates(array $dates)
15666  {
15667  $this->dates = $dates;
15668  return $this;
15669  }
15670  public function setFilters(array $filters)
15671  {
15672  $this->filters = $filters;
15673  return $this;
15674  }
15675  public function setSort($sort)
15676  {
15677  $this->sort = $sort;
15678  return $this;
15679  }
15680  public function setPath(array $paths)
15681  {
15682  $this->paths = $paths;
15683  return $this;
15684  }
15685  public function setNotPath(array $notPaths)
15686  {
15687  $this->notPaths = $notPaths;
15688  return $this;
15689  }
15690  public function ignoreUnreadableDirs($ignore = true)
15691  {
15692  $this->ignoreUnreadableDirs = (bool) $ignore;
15693  return $this;
15694  }
15695  protected abstract function canBeUsed();
15696 }
15698 
15706 abstract class AbstractFindAdapter extends AbstractAdapter
15707 {
15708  protected $shell;
15709  public function __construct()
15710  {
15711  $this->shell = new Shell();
15712  }
15713  public function searchInDirectory($dir)
15714  {
15715  $dir = realpath($dir);
15716  if (Iterator\FileTypeFilterIterator::ONLY_DIRECTORIES === $this->mode && ($this->contains || $this->notContains)) {
15717  return new Iterator\FilePathsIterator(array(), $dir);
15718  }
15719  $command = Command::create();
15720  $find = $this->buildFindCommand($command, $dir);
15721  if ($this->followLinks) {
15722  $find->add('-follow');
15723  }
15724  $find->add('-mindepth')->add($this->minDepth + 1);
15725  if (PHP_INT_MAX !== $this->maxDepth) {
15726  $find->add('-maxdepth')->add($this->maxDepth + 1);
15727  }
15728  if (Iterator\FileTypeFilterIterator::ONLY_DIRECTORIES === $this->mode) {
15729  $find->add('-type d');
15730  } elseif (Iterator\FileTypeFilterIterator::ONLY_FILES === $this->mode) {
15731  $find->add('-type f');
15732  }
15733  $this->buildNamesFiltering($find, $this->names);
15734  $this->buildNamesFiltering($find, $this->notNames, true);
15735  $this->buildPathsFiltering($find, $dir, $this->paths);
15736  $this->buildPathsFiltering($find, $dir, $this->notPaths, true);
15737  $this->buildSizesFiltering($find, $this->sizes);
15738  $this->buildDatesFiltering($find, $this->dates);
15739  $useGrep = $this->shell->testCommand('grep') && $this->shell->testCommand('xargs');
15740  $useSort = is_int($this->sort) && $this->shell->testCommand('sort') && $this->shell->testCommand('cut');
15741  if ($useGrep && ($this->contains || $this->notContains)) {
15742  $grep = $command->ins('grep');
15743  $this->buildContentFiltering($grep, $this->contains);
15744  $this->buildContentFiltering($grep, $this->notContains, true);
15745  }
15746  if ($useSort) {
15747  $this->buildSorting($command, $this->sort);
15748  }
15749  $command->setErrorHandler($this->ignoreUnreadableDirs ? function ($stderr) {
15750  return;
15751  } : function ($stderr) {
15752  throw new AccessDeniedException($stderr);
15753  });
15754  $paths = $this->shell->testCommand('uniq') ? $command->add('| uniq')->execute() : array_unique($command->execute());
15755  $iterator = new Iterator\FilePathsIterator($paths, $dir);
15756  if ($this->exclude) {
15757  $iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude);
15758  }
15759  if (!$useGrep && ($this->contains || $this->notContains)) {
15760  $iterator = new Iterator\FilecontentFilterIterator($iterator, $this->contains, $this->notContains);
15761  }
15762  if ($this->filters) {
15763  $iterator = new Iterator\CustomFilterIterator($iterator, $this->filters);
15764  }
15765  if (!$useSort && $this->sort) {
15766  $iteratorAggregate = new Iterator\SortableIterator($iterator, $this->sort);
15767  $iterator = $iteratorAggregate->getIterator();
15768  }
15769  return $iterator;
15770  }
15771  protected function canBeUsed()
15772  {
15773  return $this->shell->testCommand('find');
15774  }
15775  protected function buildFindCommand(Command $command, $dir)
15776  {
15777  return $command->ins('find')->add('find ')->arg($dir)->add('-noleaf');
15778  }
15779  private function buildNamesFiltering(Command $command, array $names, $not = false)
15780  {
15781  if (0 === count($names)) {
15782  return;
15783  }
15784  $command->add($not ? '-not' : null)->cmd('(');
15785  foreach ($names as $i => $name) {
15786  $expr = Expression::create($name);
15787  if ($expr->isGlob() && $expr->getGlob()->isExpandable()) {
15788  $expr = Expression::create($expr->getGlob()->toRegex(false));
15789  }
15790  if ($expr->isRegex()) {
15791  $regex = $expr->getRegex();
15792  $regex->prepend($regex->hasStartFlag() ? '/' : '/[^/]*')->setStartFlag(false)->setStartJoker(true)->replaceJokers('[^/]');
15793  if (!$regex->hasEndFlag() || $regex->hasEndJoker()) {
15794  $regex->setEndJoker(false)->append('[^/]*');
15795  }
15796  }
15797  $command->add($i > 0 ? '-or' : null)->add($expr->isRegex() ? $expr->isCaseSensitive() ? '-regex' : '-iregex' : ($expr->isCaseSensitive() ? '-name' : '-iname'))->arg($expr->renderPattern());
15798  }
15799  $command->cmd(')');
15800  }
15801  private function buildPathsFiltering(Command $command, $dir, array $paths, $not = false)
15802  {
15803  if (0 === count($paths)) {
15804  return;
15805  }
15806  $command->add($not ? '-not' : null)->cmd('(');
15807  foreach ($paths as $i => $path) {
15808  $expr = Expression::create($path);
15809  if ($expr->isGlob() && $expr->getGlob()->isExpandable()) {
15810  $expr = Expression::create($expr->getGlob()->toRegex(false));
15811  }
15812  if ($expr->isRegex()) {
15813  $regex = $expr->getRegex();
15814  $regex->prepend($regex->hasStartFlag() ? preg_quote($dir) . DIRECTORY_SEPARATOR : '.*')->setEndJoker(!$regex->hasEndFlag());
15815  } else {
15816  $expr->prepend('*')->append('*');
15817  }
15818  $command->add($i > 0 ? '-or' : null)->add($expr->isRegex() ? $expr->isCaseSensitive() ? '-regex' : '-iregex' : ($expr->isCaseSensitive() ? '-path' : '-ipath'))->arg($expr->renderPattern());
15819  }
15820  $command->cmd(')');
15821  }
15822  private function buildSizesFiltering(Command $command, array $sizes)
15823  {
15824  foreach ($sizes as $i => $size) {
15825  $command->add($i > 0 ? '-and' : null);
15826  switch ($size->getOperator()) {
15827  case '<=':
15828  $command->add('-size -' . ($size->getTarget() + 1) . 'c');
15829  break;
15830  case '>=':
15831  $command->add('-size +' . ($size->getTarget() - 1) . 'c');
15832  break;
15833  case '>':
15834  $command->add('-size +' . $size->getTarget() . 'c');
15835  break;
15836  case '!=':
15837  $command->add('-size -' . $size->getTarget() . 'c');
15838  $command->add('-size +' . $size->getTarget() . 'c');
15839  break;
15840  case '<':
15841  default:
15842  $command->add('-size -' . $size->getTarget() . 'c');
15843  }
15844  }
15845  }
15846  private function buildDatesFiltering(Command $command, array $dates)
15847  {
15848  foreach ($dates as $i => $date) {
15849  $command->add($i > 0 ? '-and' : null);
15850  $mins = (int) round((time() - $date->getTarget()) / 60);
15851  if (0 > $mins) {
15852  $command->add(' -mmin -0');
15853  return;
15854  }
15855  switch ($date->getOperator()) {
15856  case '<=':
15857  $command->add('-mmin +' . ($mins - 1));
15858  break;
15859  case '>=':
15860  $command->add('-mmin -' . ($mins + 1));
15861  break;
15862  case '>':
15863  $command->add('-mmin -' . $mins);
15864  break;
15865  case '!=':
15866  $command->add('-mmin +' . $mins . ' -or -mmin -' . $mins);
15867  break;
15868  case '<':
15869  default:
15870  $command->add('-mmin +' . $mins);
15871  }
15872  }
15873  }
15874  private function buildSorting(Command $command, $sort)
15875  {
15876  $this->buildFormatSorting($command, $sort);
15877  }
15878  protected abstract function buildFormatSorting(Command $command, $sort);
15879  protected abstract function buildContentFiltering(Command $command, array $contains, $not = false);
15880 }
15882 
15888 {
15889  public function getName()
15890  {
15891  return 'gnu_find';
15892  }
15893  protected function buildFormatSorting(Command $command, $sort)
15894  {
15895  switch ($sort) {
15896  case SortableIterator::SORT_BY_NAME:
15897  $command->ins('sort')->add('| sort');
15898  return;
15899  case SortableIterator::SORT_BY_TYPE:
15900  $format = '%y';
15901  break;
15902  case SortableIterator::SORT_BY_ACCESSED_TIME:
15903  $format = '%A@';
15904  break;
15905  case SortableIterator::SORT_BY_CHANGED_TIME:
15906  $format = '%C@';
15907  break;
15908  case SortableIterator::SORT_BY_MODIFIED_TIME:
15909  $format = '%T@';
15910  break;
15911  default:
15912  throw new \InvalidArgumentException(sprintf('Unknown sort options: %s.', $sort));
15913  }
15914  $command->get('find')->add('-printf')->arg($format . ' %h/%f\\n')->add('| sort | cut')->arg('-d ')->arg('-f2-');
15915  }
15916  protected function canBeUsed()
15917  {
15918  return $this->shell->getType() === Shell::TYPE_UNIX && parent::canBeUsed();
15919  }
15920  protected function buildFindCommand(Command $command, $dir)
15921  {
15922  return parent::buildFindCommand($command, $dir)->add('-regextype posix-extended');
15923  }
15924  protected function buildContentFiltering(Command $command, array $contains, $not = false)
15925  {
15926  foreach ($contains as $contain) {
15927  $expr = Expression::create($contain);
15928  $command->add('| xargs -I{} -r grep -I')->add($expr->isCaseSensitive() ? null : '-i')->add($not ? '-L' : '-l')->add('-Ee')->arg($expr->renderPattern())->add('{}');
15929  }
15930  }
15931 }
15933 
15936 {
15937  public function searchInDirectory($dir)
15938  {
15939  $flags = \RecursiveDirectoryIterator::SKIP_DOTS;
15940  if ($this->followLinks) {
15941  $flags |= \RecursiveDirectoryIterator::FOLLOW_SYMLINKS;
15942  }
15943  $iterator = new \RecursiveIteratorIterator(new Iterator\RecursiveDirectoryIterator($dir, $flags, $this->ignoreUnreadableDirs), \RecursiveIteratorIterator::SELF_FIRST);
15944  if ($this->minDepth > 0 || $this->maxDepth < PHP_INT_MAX) {
15945  $iterator = new Iterator\DepthRangeFilterIterator($iterator, $this->minDepth, $this->maxDepth);
15946  }
15947  if ($this->mode) {
15948  $iterator = new Iterator\FileTypeFilterIterator($iterator, $this->mode);
15949  }
15950  if ($this->exclude) {
15951  $iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude);
15952  }
15953  if ($this->names || $this->notNames) {
15954  $iterator = new Iterator\FilenameFilterIterator($iterator, $this->names, $this->notNames);
15955  }
15956  if ($this->contains || $this->notContains) {
15957  $iterator = new Iterator\FilecontentFilterIterator($iterator, $this->contains, $this->notContains);
15958  }
15959  if ($this->sizes) {
15960  $iterator = new Iterator\SizeRangeFilterIterator($iterator, $this->sizes);
15961  }
15962  if ($this->dates) {
15963  $iterator = new Iterator\DateRangeFilterIterator($iterator, $this->dates);
15964  }
15965  if ($this->filters) {
15966  $iterator = new Iterator\CustomFilterIterator($iterator, $this->filters);
15967  }
15968  if ($this->sort) {
15969  $iteratorAggregate = new Iterator\SortableIterator($iterator, $this->sort);
15970  $iterator = $iteratorAggregate->getIterator();
15971  }
15972  if ($this->paths || $this->notPaths) {
15973  $iterator = new Iterator\PathFilterIterator($iterator, $this->paths, $this->notPaths);
15974  }
15975  return $iterator;
15976  }
15977  public function getName()
15978  {
15979  return 'php';
15980  }
15981  protected function canBeUsed()
15982  {
15983  return true;
15984  }
15985 }
15987 
15993 {
15994  public function getName()
15995  {
15996  return 'bsd_find';
15997  }
15998  protected function canBeUsed()
15999  {
16000  return in_array($this->shell->getType(), array(Shell::TYPE_BSD, Shell::TYPE_DARWIN)) && parent::canBeUsed();
16001  }
16002  protected function buildFormatSorting(Command $command, $sort)
16003  {
16004  switch ($sort) {
16005  case SortableIterator::SORT_BY_NAME:
16006  $command->ins('sort')->add('| sort');
16007  return;
16008  case SortableIterator::SORT_BY_TYPE:
16009  $format = '%HT';
16010  break;
16011  case SortableIterator::SORT_BY_ACCESSED_TIME:
16012  $format = '%a';
16013  break;
16014  case SortableIterator::SORT_BY_CHANGED_TIME:
16015  $format = '%c';
16016  break;
16017  case SortableIterator::SORT_BY_MODIFIED_TIME:
16018  $format = '%m';
16019  break;
16020  default:
16021  throw new \InvalidArgumentException(sprintf('Unknown sort options: %s.', $sort));
16022  }
16023  $command->add('-print0 | xargs -0 stat -f')->arg($format . '%t%N')->add('| sort | cut -f 2');
16024  }
16025  protected function buildFindCommand(Command $command, $dir)
16026  {
16027  parent::buildFindCommand($command, $dir)->addAtIndex('-E', 1);
16028  return $command;
16029  }
16030  protected function buildContentFiltering(Command $command, array $contains, $not = false)
16031  {
16032  foreach ($contains as $contain) {
16033  $expr = Expression::create($contain);
16034  $command->add('| grep -v \'^$\'')->add('| xargs -I{} grep -I')->add($expr->isCaseSensitive() ? null : '-i')->add($not ? '-L' : '-l')->add('-Ee')->arg($expr->renderPattern())->add('{}');
16035  }
16036  }
16037 }
16038 namespace Symfony\Component\Finder;
16039 
16055 class Finder implements \IteratorAggregate, \Countable
16056 {
16057  const IGNORE_VCS_FILES = 1;
16058  const IGNORE_DOT_FILES = 2;
16059  private $mode = 0;
16060  private $names = array();
16061  private $notNames = array();
16062  private $exclude = array();
16063  private $filters = array();
16064  private $depths = array();
16065  private $sizes = array();
16066  private $followLinks = false;
16067  private $sort = false;
16068  private $ignore = 0;
16069  private $dirs = array();
16070  private $dates = array();
16071  private $iterators = array();
16072  private $contains = array();
16073  private $notContains = array();
16074  private $adapters = array();
16075  private $paths = array();
16076  private $notPaths = array();
16077  private $ignoreUnreadableDirs = false;
16078  private static $vcsPatterns = array('.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg');
16079  public function __construct()
16080  {
16081  $this->ignore = static::IGNORE_VCS_FILES | static::IGNORE_DOT_FILES;
16082  $this->addAdapter(new GnuFindAdapter())->addAdapter(new BsdFindAdapter())->addAdapter(new PhpAdapter(), -50)->setAdapter('php');
16083  }
16084  public static function create()
16085  {
16086  return new static();
16087  }
16088  public function addAdapter(AdapterInterface $adapter, $priority = 0)
16089  {
16090  $this->adapters[$adapter->getName()] = array('adapter' => $adapter, 'priority' => $priority, 'selected' => false);
16091  return $this->sortAdapters();
16092  }
16093  public function useBestAdapter()
16094  {
16095  $this->resetAdapterSelection();
16096  return $this->sortAdapters();
16097  }
16098  public function setAdapter($name)
16099  {
16100  if (!isset($this->adapters[$name])) {
16101  throw new \InvalidArgumentException(sprintf('Adapter "%s" does not exist.', $name));
16102  }
16103  $this->resetAdapterSelection();
16104  $this->adapters[$name]['selected'] = true;
16105  return $this->sortAdapters();
16106  }
16107  public function removeAdapters()
16108  {
16109  $this->adapters = array();
16110  return $this;
16111  }
16112  public function getAdapters()
16113  {
16114  return array_values(array_map(function (array $adapter) {
16115  return $adapter['adapter'];
16116  }, $this->adapters));
16117  }
16118  public function directories()
16119  {
16120  $this->mode = Iterator\FileTypeFilterIterator::ONLY_DIRECTORIES;
16121  return $this;
16122  }
16123  public function files()
16124  {
16125  $this->mode = Iterator\FileTypeFilterIterator::ONLY_FILES;
16126  return $this;
16127  }
16128  public function depth($level)
16129  {
16130  $this->depths[] = new Comparator\NumberComparator($level);
16131  return $this;
16132  }
16133  public function date($date)
16134  {
16135  $this->dates[] = new Comparator\DateComparator($date);
16136  return $this;
16137  }
16138  public function name($pattern)
16139  {
16140  $this->names[] = $pattern;
16141  return $this;
16142  }
16143  public function notName($pattern)
16144  {
16145  $this->notNames[] = $pattern;
16146  return $this;
16147  }
16148  public function contains($pattern)
16149  {
16150  $this->contains[] = $pattern;
16151  return $this;
16152  }
16153  public function notContains($pattern)
16154  {
16155  $this->notContains[] = $pattern;
16156  return $this;
16157  }
16158  public function path($pattern)
16159  {
16160  $this->paths[] = $pattern;
16161  return $this;
16162  }
16163  public function notPath($pattern)
16164  {
16165  $this->notPaths[] = $pattern;
16166  return $this;
16167  }
16168  public function size($size)
16169  {
16170  $this->sizes[] = new Comparator\NumberComparator($size);
16171  return $this;
16172  }
16173  public function exclude($dirs)
16174  {
16175  $this->exclude = array_merge($this->exclude, (array) $dirs);
16176  return $this;
16177  }
16178  public function ignoreDotFiles($ignoreDotFiles)
16179  {
16180  if ($ignoreDotFiles) {
16181  $this->ignore |= static::IGNORE_DOT_FILES;
16182  } else {
16183  $this->ignore &= ~static::IGNORE_DOT_FILES;
16184  }
16185  return $this;
16186  }
16187  public function ignoreVCS($ignoreVCS)
16188  {
16189  if ($ignoreVCS) {
16190  $this->ignore |= static::IGNORE_VCS_FILES;
16191  } else {
16192  $this->ignore &= ~static::IGNORE_VCS_FILES;
16193  }
16194  return $this;
16195  }
16196  public static function addVCSPattern($pattern)
16197  {
16198  foreach ((array) $pattern as $p) {
16199  self::$vcsPatterns[] = $p;
16200  }
16201  self::$vcsPatterns = array_unique(self::$vcsPatterns);
16202  }
16203  public function sort(\Closure $closure)
16204  {
16205  $this->sort = $closure;
16206  return $this;
16207  }
16208  public function sortByName()
16209  {
16210  $this->sort = Iterator\SortableIterator::SORT_BY_NAME;
16211  return $this;
16212  }
16213  public function sortByType()
16214  {
16215  $this->sort = Iterator\SortableIterator::SORT_BY_TYPE;
16216  return $this;
16217  }
16218  public function sortByAccessedTime()
16219  {
16220  $this->sort = Iterator\SortableIterator::SORT_BY_ACCESSED_TIME;
16221  return $this;
16222  }
16223  public function sortByChangedTime()
16224  {
16225  $this->sort = Iterator\SortableIterator::SORT_BY_CHANGED_TIME;
16226  return $this;
16227  }
16228  public function sortByModifiedTime()
16229  {
16230  $this->sort = Iterator\SortableIterator::SORT_BY_MODIFIED_TIME;
16231  return $this;
16232  }
16233  public function filter(\Closure $closure)
16234  {
16235  $this->filters[] = $closure;
16236  return $this;
16237  }
16238  public function followLinks()
16239  {
16240  $this->followLinks = true;
16241  return $this;
16242  }
16243  public function ignoreUnreadableDirs($ignore = true)
16244  {
16245  $this->ignoreUnreadableDirs = (bool) $ignore;
16246  return $this;
16247  }
16248  public function in($dirs)
16249  {
16250  $resolvedDirs = array();
16251  foreach ((array) $dirs as $dir) {
16252  if (is_dir($dir)) {
16253  $resolvedDirs[] = $dir;
16254  } elseif ($glob = glob($dir, GLOB_BRACE | GLOB_ONLYDIR)) {
16255  $resolvedDirs = array_merge($resolvedDirs, $glob);
16256  } else {
16257  throw new \InvalidArgumentException(sprintf('The "%s" directory does not exist.', $dir));
16258  }
16259  }
16260  $this->dirs = array_merge($this->dirs, $resolvedDirs);
16261  return $this;
16262  }
16263  public function getIterator()
16264  {
16265  if (0 === count($this->dirs) && 0 === count($this->iterators)) {
16266  throw new \LogicException('You must call one of in() or append() methods before iterating over a Finder.');
16267  }
16268  if (1 === count($this->dirs) && 0 === count($this->iterators)) {
16269  return $this->searchInDirectory($this->dirs[0]);
16270  }
16271  $iterator = new \AppendIterator();
16272  foreach ($this->dirs as $dir) {
16273  $iterator->append($this->searchInDirectory($dir));
16274  }
16275  foreach ($this->iterators as $it) {
16276  $iterator->append($it);
16277  }
16278  return $iterator;
16279  }
16280  public function append($iterator)
16281  {
16282  if ($iterator instanceof \IteratorAggregate) {
16283  $this->iterators[] = $iterator->getIterator();
16284  } elseif ($iterator instanceof \Iterator) {
16285  $this->iterators[] = $iterator;
16286  } elseif ($iterator instanceof \Traversable || is_array($iterator)) {
16287  $it = new \ArrayIterator();
16288  foreach ($iterator as $file) {
16289  $it->append($file instanceof \SplFileInfo ? $file : new \SplFileInfo($file));
16290  }
16291  $this->iterators[] = $it;
16292  } else {
16293  throw new \InvalidArgumentException('Finder::append() method wrong argument type.');
16294  }
16295  return $this;
16296  }
16297  public function count()
16298  {
16299  return iterator_count($this->getIterator());
16300  }
16301  private function sortAdapters()
16302  {
16303  uasort($this->adapters, function (array $a, array $b) {
16304  if ($a['selected'] || $b['selected']) {
16305  return $a['selected'] ? -1 : 1;
16306  }
16307  return $a['priority'] > $b['priority'] ? -1 : 1;
16308  });
16309  return $this;
16310  }
16311  private function searchInDirectory($dir)
16312  {
16313  if (static::IGNORE_VCS_FILES === (static::IGNORE_VCS_FILES & $this->ignore)) {
16314  $this->exclude = array_merge($this->exclude, self::$vcsPatterns);
16315  }
16316  if (static::IGNORE_DOT_FILES === (static::IGNORE_DOT_FILES & $this->ignore)) {
16317  $this->notPaths[] = '#(^|/)\\..+(/|$)#';
16318  }
16319  foreach ($this->adapters as $adapter) {
16320  if ($adapter['adapter']->isSupported()) {
16321  try {
16322  return $this->buildAdapter($adapter['adapter'])->searchInDirectory($dir);
16323  } catch (ExceptionInterface $e) {
16324  }
16325  }
16326  }
16327  throw new \RuntimeException('No supported adapter found.');
16328  }
16329  private function buildAdapter(AdapterInterface $adapter)
16330  {
16331  return $adapter->setFollowLinks($this->followLinks)->setDepths($this->depths)->setMode($this->mode)->setExclude($this->exclude)->setNames($this->names)->setNotNames($this->notNames)->setContains($this->contains)->setNotContains($this->notContains)->setSizes($this->sizes)->setDates($this->dates)->setFilters($this->filters)->setSort($this->sort)->setPath($this->paths)->setNotPath($this->notPaths)->ignoreUnreadableDirs($this->ignoreUnreadableDirs);
16332  }
16333  private function resetAdapterSelection()
16334  {
16335  $this->adapters = array_map(function (array $properties) {
16336  $properties['selected'] = false;
16337  return $properties;
16338  }, $this->adapters);
16339  }
16340 }
16341 namespace Carbon;
16342 
16343 use Closure;
16344 use DateTime;
16345 use DateTimeZone;
16346 use DateInterval;
16347 use DatePeriod;
16348 use InvalidArgumentException;
16352 class Carbon extends DateTime
16353 {
16354  const SUNDAY = 0;
16355  const MONDAY = 1;
16356  const TUESDAY = 2;
16357  const WEDNESDAY = 3;
16358  const THURSDAY = 4;
16359  const FRIDAY = 5;
16360  const SATURDAY = 6;
16361  protected static $days = array(self::SUNDAY => 'Sunday', self::MONDAY => 'Monday', self::TUESDAY => 'Tuesday', self::WEDNESDAY => 'Wednesday', self::THURSDAY => 'Thursday', self::FRIDAY => 'Friday', self::SATURDAY => 'Saturday');
16362  protected static $relativeKeywords = array('this', 'next', 'last', 'tomorrow', 'yesterday', '+', '-', 'first', 'last', 'ago');
16363  const YEARS_PER_CENTURY = 100;
16364  const YEARS_PER_DECADE = 10;
16365  const MONTHS_PER_YEAR = 12;
16366  const WEEKS_PER_YEAR = 52;
16367  const DAYS_PER_WEEK = 7;
16368  const HOURS_PER_DAY = 24;
16369  const MINUTES_PER_HOUR = 60;
16370  const SECONDS_PER_MINUTE = 60;
16371  const DEFAULT_TO_STRING_FORMAT = 'Y-m-d H:i:s';
16372  protected static $toStringFormat = self::DEFAULT_TO_STRING_FORMAT;
16373  protected static $testNow;
16374  protected static $translator;
16375  protected static function safeCreateDateTimeZone($object)
16376  {
16377  if ($object === null) {
16378  return new DateTimeZone(date_default_timezone_get());
16379  }
16380  if ($object instanceof DateTimeZone) {
16381  return $object;
16382  }
16383  $tz = @timezone_open((string) $object);
16384  if ($tz === false) {
16385  throw new InvalidArgumentException('Unknown or bad timezone (' . $object . ')');
16386  }
16387  return $tz;
16388  }
16389  public function __construct($time = null, $tz = null)
16390  {
16391  if (static::hasTestNow() && (empty($time) || $time === 'now' || static::hasRelativeKeywords($time))) {
16392  $testInstance = clone static::getTestNow();
16393  if (static::hasRelativeKeywords($time)) {
16394  $testInstance->modify($time);
16395  }
16396  if ($tz !== NULL && $tz != static::getTestNow()->tz) {
16397  $testInstance->setTimezone($tz);
16398  } else {
16399  $tz = $testInstance->tz;
16400  }
16401  $time = $testInstance->toDateTimeString();
16402  }
16403  parent::__construct($time, static::safeCreateDateTimeZone($tz));
16404  }
16405  public static function instance(DateTime $dt)
16406  {
16407  return new static($dt->format('Y-m-d H:i:s.u'), $dt->getTimeZone());
16408  }
16409  public static function parse($time = null, $tz = null)
16410  {
16411  return new static($time, $tz);
16412  }
16413  public static function now($tz = null)
16414  {
16415  return new static(null, $tz);
16416  }
16417  public static function today($tz = null)
16418  {
16419  return static::now($tz)->startOfDay();
16420  }
16421  public static function tomorrow($tz = null)
16422  {
16423  return static::today($tz)->addDay();
16424  }
16425  public static function yesterday($tz = null)
16426  {
16427  return static::today($tz)->subDay();
16428  }
16429  public static function maxValue()
16430  {
16431  return static::createFromTimestamp(PHP_INT_MAX);
16432  }
16433  public static function minValue()
16434  {
16435  return static::createFromTimestamp(~PHP_INT_MAX);
16436  }
16437  public static function create($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $tz = null)
16438  {
16439  $year = $year === null ? date('Y') : $year;
16440  $month = $month === null ? date('n') : $month;
16441  $day = $day === null ? date('j') : $day;
16442  if ($hour === null) {
16443  $hour = date('G');
16444  $minute = $minute === null ? date('i') : $minute;
16445  $second = $second === null ? date('s') : $second;
16446  } else {
16447  $minute = $minute === null ? 0 : $minute;
16448  $second = $second === null ? 0 : $second;
16449  }
16450  return static::createFromFormat('Y-n-j G:i:s', sprintf('%s-%s-%s %s:%02s:%02s', $year, $month, $day, $hour, $minute, $second), $tz);
16451  }
16452  public static function createFromDate($year = null, $month = null, $day = null, $tz = null)
16453  {
16454  return static::create($year, $month, $day, null, null, null, $tz);
16455  }
16456  public static function createFromTime($hour = null, $minute = null, $second = null, $tz = null)
16457  {
16458  return static::create(null, null, null, $hour, $minute, $second, $tz);
16459  }
16460  public static function createFromFormat($format, $time, $tz = null)
16461  {
16462  if ($tz !== null) {
16463  $dt = parent::createFromFormat($format, $time, static::safeCreateDateTimeZone($tz));
16464  } else {
16465  $dt = parent::createFromFormat($format, $time);
16466  }
16467  if ($dt instanceof DateTime) {
16468  return static::instance($dt);
16469  }
16470  $errors = static::getLastErrors();
16471  throw new InvalidArgumentException(implode(PHP_EOL, $errors['errors']));
16472  }
16473  public static function createFromTimestamp($timestamp, $tz = null)
16474  {
16475  return static::now($tz)->setTimestamp($timestamp);
16476  }
16477  public static function createFromTimestampUTC($timestamp)
16478  {
16479  return new static('@' . $timestamp);
16480  }
16481  public function copy()
16482  {
16483  return static::instance($this);
16484  }
16485  public function __get($name)
16486  {
16487  switch (true) {
16488  case array_key_exists($name, $formats = array('year' => 'Y', 'yearIso' => 'o', 'month' => 'n', 'day' => 'j', 'hour' => 'G', 'minute' => 'i', 'second' => 's', 'micro' => 'u', 'dayOfWeek' => 'w', 'dayOfYear' => 'z', 'weekOfYear' => 'W', 'daysInMonth' => 't', 'timestamp' => 'U')):
16489  return (int) $this->format($formats[$name]);
16490  case $name === 'weekOfMonth':
16491  return (int) ceil($this->day / static::DAYS_PER_WEEK);
16492  case $name === 'age':
16493  return (int) $this->diffInYears();
16494  case $name === 'quarter':
16495  return (int) ceil($this->month / 3);
16496  case $name === 'offset':
16497  return $this->getOffset();
16498  case $name === 'offsetHours':
16499  return $this->getOffset() / static::SECONDS_PER_MINUTE / static::MINUTES_PER_HOUR;
16500  case $name === 'dst':
16501  return $this->format('I') == '1';
16502  case $name === 'local':
16503  return $this->offset == $this->copy()->setTimezone(date_default_timezone_get())->offset;
16504  case $name === 'utc':
16505  return $this->offset == 0;
16506  case $name === 'timezone' || $name === 'tz':
16507  return $this->getTimezone();
16508  case $name === 'timezoneName' || $name === 'tzName':
16509  return $this->getTimezone()->getName();
16510  default:
16511  throw new InvalidArgumentException(sprintf('Unknown getter \'%s\'', $name));
16512  }
16513  }
16514  public function __isset($name)
16515  {
16516  try {
16517  $this->__get($name);
16518  } catch (InvalidArgumentException $e) {
16519  return false;
16520  }
16521  return true;
16522  }
16523  public function __set($name, $value)
16524  {
16525  switch ($name) {
16526  case 'year':
16527  $this->setDate($value, $this->month, $this->day);
16528  break;
16529  case 'month':
16530  $this->setDate($this->year, $value, $this->day);
16531  break;
16532  case 'day':
16533  $this->setDate($this->year, $this->month, $value);
16534  break;
16535  case 'hour':
16536  $this->setTime($value, $this->minute, $this->second);
16537  break;
16538  case 'minute':
16539  $this->setTime($this->hour, $value, $this->second);
16540  break;
16541  case 'second':
16542  $this->setTime($this->hour, $this->minute, $value);
16543  break;
16544  case 'timestamp':
16545  parent::setTimestamp($value);
16546  break;
16547  case 'timezone':
16548  case 'tz':
16549  $this->setTimezone($value);
16550  break;
16551  default:
16552  throw new InvalidArgumentException(sprintf('Unknown setter \'%s\'', $name));
16553  }
16554  }
16555  public function year($value)
16556  {
16557  $this->year = $value;
16558  return $this;
16559  }
16560  public function month($value)
16561  {
16562  $this->month = $value;
16563  return $this;
16564  }
16565  public function day($value)
16566  {
16567  $this->day = $value;
16568  return $this;
16569  }
16570  public function hour($value)
16571  {
16572  $this->hour = $value;
16573  return $this;
16574  }
16575  public function minute($value)
16576  {
16577  $this->minute = $value;
16578  return $this;
16579  }
16580  public function second($value)
16581  {
16582  $this->second = $value;
16583  return $this;
16584  }
16585  public function setDateTime($year, $month, $day, $hour, $minute, $second = 0)
16586  {
16587  return $this->setDate($year, $month, $day)->setTime($hour, $minute, $second);
16588  }
16589  public function timestamp($value)
16590  {
16591  $this->timestamp = $value;
16592  return $this;
16593  }
16594  public function timezone($value)
16595  {
16596  return $this->setTimezone($value);
16597  }
16598  public function tz($value)
16599  {
16600  return $this->setTimezone($value);
16601  }
16602  public function setTimezone($value)
16603  {
16604  parent::setTimezone(static::safeCreateDateTimeZone($value));
16605  return $this;
16606  }
16607  public static function setTestNow(Carbon $testNow = null)
16608  {
16609  static::$testNow = $testNow;
16610  }
16611  public static function getTestNow()
16612  {
16613  return static::$testNow;
16614  }
16615  public static function hasTestNow()
16616  {
16617  return static::getTestNow() !== null;
16618  }
16619  public static function hasRelativeKeywords($time)
16620  {
16621  if (preg_match('/[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}/', $time) !== 1) {
16622  foreach (static::$relativeKeywords as $keyword) {
16623  if (stripos($time, $keyword) !== false) {
16624  return true;
16625  }
16626  }
16627  }
16628  return false;
16629  }
16630  protected static function translator()
16631  {
16632  if (static::$translator == null) {
16633  static::$translator = new Translator('en');
16634  static::$translator->addLoader('array', new ArrayLoader());
16635  static::setLocale('en');
16636  }
16637  return static::$translator;
16638  }
16639  public static function getTranslator()
16640  {
16641  return static::translator();
16642  }
16643  public static function setTranslator(TranslatorInterface $translator)
16644  {
16645  static::$translator = $translator;
16646  }
16647  public static function getLocale()
16648  {
16649  return static::translator()->getLocale();
16650  }
16651  public static function setLocale($locale)
16652  {
16653  static::translator()->setLocale($locale);
16654  static::translator()->addResource('array', require '/Users/ket/Desktop/VirtualScada/virtualscada_laravel/vendor/nesbot/carbon/src/Carbon' . '/Lang/' . $locale . '.php', $locale);
16655  }
16656  public function formatLocalized($format)
16657  {
16658  if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
16659  $format = preg_replace('#(?<!%)((?:%%)*)%e#', '\\1%#d', $format);
16660  }
16661  return strftime($format, strtotime($this));
16662  }
16663  public static function resetToStringFormat()
16664  {
16665  static::setToStringFormat(static::DEFAULT_TO_STRING_FORMAT);
16666  }
16667  public static function setToStringFormat($format)
16668  {
16669  static::$toStringFormat = $format;
16670  }
16671  public function __toString()
16672  {
16673  return $this->format(static::$toStringFormat);
16674  }
16675  public function toDateString()
16676  {
16677  return $this->format('Y-m-d');
16678  }
16679  public function toFormattedDateString()
16680  {
16681  return $this->format('M j, Y');
16682  }
16683  public function toTimeString()
16684  {
16685  return $this->format('H:i:s');
16686  }
16687  public function toDateTimeString()
16688  {
16689  return $this->format('Y-m-d H:i:s');
16690  }
16691  public function toDayDateTimeString()
16692  {
16693  return $this->format('D, M j, Y g:i A');
16694  }
16695  public function toAtomString()
16696  {
16697  return $this->format(static::ATOM);
16698  }
16699  public function toCookieString()
16700  {
16701  return $this->format(static::COOKIE);
16702  }
16703  public function toIso8601String()
16704  {
16705  return $this->format(static::ISO8601);
16706  }
16707  public function toRfc822String()
16708  {
16709  return $this->format(static::RFC822);
16710  }
16711  public function toRfc850String()
16712  {
16713  return $this->format(static::RFC850);
16714  }
16715  public function toRfc1036String()
16716  {
16717  return $this->format(static::RFC1036);
16718  }
16719  public function toRfc1123String()
16720  {
16721  return $this->format(static::RFC1123);
16722  }
16723  public function toRfc2822String()
16724  {
16725  return $this->format(static::RFC2822);
16726  }
16727  public function toRfc3339String()
16728  {
16729  return $this->format(static::RFC3339);
16730  }
16731  public function toRssString()
16732  {
16733  return $this->format(static::RSS);
16734  }
16735  public function toW3cString()
16736  {
16737  return $this->format(static::W3C);
16738  }
16739  public function eq(Carbon $dt)
16740  {
16741  return $this == $dt;
16742  }
16743  public function ne(Carbon $dt)
16744  {
16745  return !$this->eq($dt);
16746  }
16747  public function gt(Carbon $dt)
16748  {
16749  return $this > $dt;
16750  }
16751  public function gte(Carbon $dt)
16752  {
16753  return $this >= $dt;
16754  }
16755  public function lt(Carbon $dt)
16756  {
16757  return $this < $dt;
16758  }
16759  public function lte(Carbon $dt)
16760  {
16761  return $this <= $dt;
16762  }
16763  public function between(Carbon $dt1, Carbon $dt2, $equal = true)
16764  {
16765  if ($dt1->gt($dt2)) {
16766  $temp = $dt1;
16767  $dt1 = $dt2;
16768  $dt2 = $temp;
16769  }
16770  if ($equal) {
16771  return $this->gte($dt1) && $this->lte($dt2);
16772  } else {
16773  return $this->gt($dt1) && $this->lt($dt2);
16774  }
16775  }
16776  public function min(Carbon $dt = null)
16777  {
16778  $dt = $dt === null ? static::now($this->tz) : $dt;
16779  return $this->lt($dt) ? $this : $dt;
16780  }
16781  public function max(Carbon $dt = null)
16782  {
16783  $dt = $dt === null ? static::now($this->tz) : $dt;
16784  return $this->gt($dt) ? $this : $dt;
16785  }
16786  public function isWeekday()
16787  {
16788  return $this->dayOfWeek != static::SUNDAY && $this->dayOfWeek != static::SATURDAY;
16789  }
16790  public function isWeekend()
16791  {
16792  return !$this->isWeekDay();
16793  }
16794  public function isYesterday()
16795  {
16796  return $this->toDateString() === static::yesterday($this->tz)->toDateString();
16797  }
16798  public function isToday()
16799  {
16800  return $this->toDateString() === static::now($this->tz)->toDateString();
16801  }
16802  public function isTomorrow()
16803  {
16804  return $this->toDateString() === static::tomorrow($this->tz)->toDateString();
16805  }
16806  public function isFuture()
16807  {
16808  return $this->gt(static::now($this->tz));
16809  }
16810  public function isPast()
16811  {
16812  return $this->lt(static::now($this->tz));
16813  }
16814  public function isLeapYear()
16815  {
16816  return $this->format('L') == '1';
16817  }
16818  public function isSameDay(Carbon $dt)
16819  {
16820  return $this->toDateString() === $dt->toDateString();
16821  }
16822  public function addYears($value)
16823  {
16824  return $this->modify((int) $value . ' year');
16825  }
16826  public function addYear($value = 1)
16827  {
16828  return $this->addYears($value);
16829  }
16830  public function subYear($value = 1)
16831  {
16832  return $this->subYears($value);
16833  }
16834  public function subYears($value)
16835  {
16836  return $this->addYears(-1 * $value);
16837  }
16838  public function addMonths($value)
16839  {
16840  return $this->modify((int) $value . ' month');
16841  }
16842  public function addMonth($value = 1)
16843  {
16844  return $this->addMonths($value);
16845  }
16846  public function subMonth($value = 1)
16847  {
16848  return $this->subMonths($value);
16849  }
16850  public function subMonths($value)
16851  {
16852  return $this->addMonths(-1 * $value);
16853  }
16854  public function addMonthsNoOverflow($value)
16855  {
16856  $date = $this->copy()->addMonths($value);
16857  if ($date->day != $this->day) {
16858  $date->day(1)->subMonth()->day($date->daysInMonth);
16859  }
16860  return $date;
16861  }
16862  public function addMonthNoOverflow($value = 1)
16863  {
16864  return $this->addMonthsNoOverflow($value);
16865  }
16866  public function subMonthNoOverflow($value = 1)
16867  {
16868  return $this->subMonthsNoOverflow($value);
16869  }
16870  public function subMonthsNoOverflow($value)
16871  {
16872  return $this->addMonthsNoOverflow(-1 * $value);
16873  }
16874  public function addDays($value)
16875  {
16876  return $this->modify((int) $value . ' day');
16877  }
16878  public function addDay($value = 1)
16879  {
16880  return $this->addDays($value);
16881  }
16882  public function subDay($value = 1)
16883  {
16884  return $this->subDays($value);
16885  }
16886  public function subDays($value)
16887  {
16888  return $this->addDays(-1 * $value);
16889  }
16890  public function addWeekdays($value)
16891  {
16892  return $this->modify((int) $value . ' weekday');
16893  }
16894  public function addWeekday($value = 1)
16895  {
16896  return $this->addWeekdays($value);
16897  }
16898  public function subWeekday($value = 1)
16899  {
16900  return $this->subWeekdays($value);
16901  }
16902  public function subWeekdays($value)
16903  {
16904  return $this->addWeekdays(-1 * $value);
16905  }
16906  public function addWeeks($value)
16907  {
16908  return $this->modify((int) $value . ' week');
16909  }
16910  public function addWeek($value = 1)
16911  {
16912  return $this->addWeeks($value);
16913  }
16914  public function subWeek($value = 1)
16915  {
16916  return $this->subWeeks($value);
16917  }
16918  public function subWeeks($value)
16919  {
16920  return $this->addWeeks(-1 * $value);
16921  }
16922  public function addHours($value)
16923  {
16924  return $this->modify((int) $value . ' hour');
16925  }
16926  public function addHour($value = 1)
16927  {
16928  return $this->addHours($value);
16929  }
16930  public function subHour($value = 1)
16931  {
16932  return $this->subHours($value);
16933  }
16934  public function subHours($value)
16935  {
16936  return $this->addHours(-1 * $value);
16937  }
16938  public function addMinutes($value)
16939  {
16940  return $this->modify((int) $value . ' minute');
16941  }
16942  public function addMinute($value = 1)
16943  {
16944  return $this->addMinutes($value);
16945  }
16946  public function subMinute($value = 1)
16947  {
16948  return $this->subMinutes($value);
16949  }
16950  public function subMinutes($value)
16951  {
16952  return $this->addMinutes(-1 * $value);
16953  }
16954  public function addSeconds($value)
16955  {
16956  return $this->modify((int) $value . ' second');
16957  }
16958  public function addSecond($value = 1)
16959  {
16960  return $this->addSeconds($value);
16961  }
16962  public function subSecond($value = 1)
16963  {
16964  return $this->subSeconds($value);
16965  }
16966  public function subSeconds($value)
16967  {
16968  return $this->addSeconds(-1 * $value);
16969  }
16970  public function diffInYears(Carbon $dt = null, $abs = true)
16971  {
16972  $dt = $dt === null ? static::now($this->tz) : $dt;
16973  return (int) $this->diff($dt, $abs)->format('%r%y');
16974  }
16975  public function diffInMonths(Carbon $dt = null, $abs = true)
16976  {
16977  $dt = $dt === null ? static::now($this->tz) : $dt;
16978  return $this->diffInYears($dt, $abs) * static::MONTHS_PER_YEAR + (int) $this->diff($dt, $abs)->format('%r%m');
16979  }
16980  public function diffInWeeks(Carbon $dt = null, $abs = true)
16981  {
16982  return (int) ($this->diffInDays($dt, $abs) / static::DAYS_PER_WEEK);
16983  }
16984  public function diffInDays(Carbon $dt = null, $abs = true)
16985  {
16986  $dt = $dt === null ? static::now($this->tz) : $dt;
16987  return (int) $this->diff($dt, $abs)->format('%r%a');
16988  }
16989  public function diffInDaysFiltered(Closure $callback, Carbon $dt = null, $abs = true)
16990  {
16991  return $this->diffFiltered(CarbonInterval::day(), $callback, $dt, $abs);
16992  }
16993  public function diffInHoursFiltered(Closure $callback, Carbon $dt = null, $abs = true)
16994  {
16995  return $this->diffFiltered(CarbonInterval::hour(), $callback, $dt, $abs);
16996  }
16997  public function diffFiltered(CarbonInterval $ci, Closure $callback, Carbon $dt = null, $abs = true)
16998  {
16999  $start = $this;
17000  $end = $dt === null ? static::now($this->tz) : $dt;
17001  $inverse = false;
17002  if ($end < $start) {
17003  $start = $end;
17004  $end = $this;
17005  $inverse = true;
17006  }
17007  $period = new DatePeriod($start, $ci, $end);
17008  $vals = array_filter(iterator_to_array($period), function (DateTime $date) use($callback) {
17009  return call_user_func($callback, Carbon::instance($date));
17010  });
17011  $diff = count($vals);
17012  return $inverse && !$abs ? -$diff : $diff;
17013  }
17014  public function diffInWeekdays(Carbon $dt = null, $abs = true)
17015  {
17016  return $this->diffInDaysFiltered(function (Carbon $date) {
17017  return $date->isWeekday();
17018  }, $dt, $abs);
17019  }
17020  public function diffInWeekendDays(Carbon $dt = null, $abs = true)
17021  {
17022  return $this->diffInDaysFiltered(function (Carbon $date) {
17023  return $date->isWeekend();
17024  }, $dt, $abs);
17025  }
17026  public function diffInHours(Carbon $dt = null, $abs = true)
17027  {
17028  return (int) ($this->diffInSeconds($dt, $abs) / static::SECONDS_PER_MINUTE / static::MINUTES_PER_HOUR);
17029  }
17030  public function diffInMinutes(Carbon $dt = null, $abs = true)
17031  {
17032  return (int) ($this->diffInSeconds($dt, $abs) / static::SECONDS_PER_MINUTE);
17033  }
17034  public function diffInSeconds(Carbon $dt = null, $abs = true)
17035  {
17036  $dt = $dt === null ? static::now($this->tz) : $dt;
17037  $value = $dt->getTimestamp() - $this->getTimestamp();
17038  return $abs ? abs($value) : $value;
17039  }
17040  public function secondsSinceMidnight()
17041  {
17042  return $this->diffInSeconds($this->copy()->startOfDay());
17043  }
17044  public function secondsUntilEndOfDay()
17045  {
17046  return $this->diffInSeconds($this->copy()->endOfDay());
17047  }
17048  public function diffForHumans(Carbon $other = null, $absolute = false)
17049  {
17050  $isNow = $other === null;
17051  if ($isNow) {
17052  $other = static::now($this->tz);
17053  }
17054  $diffInterval = $this->diff($other);
17055  switch (true) {
17056  case $diffInterval->y > 0:
17057  $unit = 'year';
17058  $count = $diffInterval->y;
17059  break;
17060  case $diffInterval->m > 0:
17061  $unit = 'month';
17062  $count = $diffInterval->m;
17063  break;
17064  case $diffInterval->d > 0:
17065  $unit = 'day';
17066  $count = $diffInterval->d;
17067  if ($count >= self::DAYS_PER_WEEK) {
17068  $unit = 'week';
17069  $count = (int) ($count / self::DAYS_PER_WEEK);
17070  }
17071  break;
17072  case $diffInterval->h > 0:
17073  $unit = 'hour';
17074  $count = $diffInterval->h;
17075  break;
17076  case $diffInterval->i > 0:
17077  $unit = 'minute';
17078  $count = $diffInterval->i;
17079  break;
17080  default:
17081  $count = $diffInterval->s;
17082  $unit = 'second';
17083  break;
17084  }
17085  if ($count == 0) {
17086  $count = 1;
17087  }
17088  $time = static::translator()->transChoice($unit, $count, array(':count' => $count));
17089  if ($absolute) {
17090  return $time;
17091  }
17092  $isFuture = $diffInterval->invert === 1;
17093  $transId = $isNow ? $isFuture ? 'from_now' : 'ago' : ($isFuture ? 'after' : 'before');
17094  $tryKeyExists = $unit . '_' . $transId;
17095  if ($tryKeyExists !== static::translator()->transChoice($tryKeyExists, $count)) {
17096  $time = static::translator()->transChoice($tryKeyExists, $count, array(':count' => $count));
17097  }
17098  return static::translator()->trans($transId, array(':time' => $time));
17099  }
17100  public function startOfDay()
17101  {
17102  return $this->hour(0)->minute(0)->second(0);
17103  }
17104  public function endOfDay()
17105  {
17106  return $this->hour(23)->minute(59)->second(59);
17107  }
17108  public function startOfMonth()
17109  {
17110  return $this->startOfDay()->day(1);
17111  }
17112  public function endOfMonth()
17113  {
17114  return $this->day($this->daysInMonth)->endOfDay();
17115  }
17116  public function startOfYear()
17117  {
17118  return $this->month(1)->startOfMonth();
17119  }
17120  public function endOfYear()
17121  {
17122  return $this->month(static::MONTHS_PER_YEAR)->endOfMonth();
17123  }
17124  public function startOfDecade()
17125  {
17126  return $this->startOfYear()->year($this->year - $this->year % static::YEARS_PER_DECADE);
17127  }
17128  public function endOfDecade()
17129  {
17130  return $this->endOfYear()->year($this->year - $this->year % static::YEARS_PER_DECADE + static::YEARS_PER_DECADE - 1);
17131  }
17132  public function startOfCentury()
17133  {
17134  return $this->startOfYear()->year($this->year - $this->year % static::YEARS_PER_CENTURY);
17135  }
17136  public function endOfCentury()
17137  {
17138  return $this->endOfYear()->year($this->year - $this->year % static::YEARS_PER_CENTURY + static::YEARS_PER_CENTURY - 1);
17139  }
17140  public function startOfWeek()
17141  {
17142  if ($this->dayOfWeek != static::MONDAY) {
17143  $this->previous(static::MONDAY);
17144  }
17145  return $this->startOfDay();
17146  }
17147  public function endOfWeek()
17148  {
17149  if ($this->dayOfWeek != static::SUNDAY) {
17150  $this->next(static::SUNDAY);
17151  }
17152  return $this->endOfDay();
17153  }
17154  public function next($dayOfWeek = null)
17155  {
17156  if ($dayOfWeek === null) {
17157  $dayOfWeek = $this->dayOfWeek;
17158  }
17159  return $this->startOfDay()->modify('next ' . static::$days[$dayOfWeek]);
17160  }
17161  public function previous($dayOfWeek = null)
17162  {
17163  if ($dayOfWeek === null) {
17164  $dayOfWeek = $this->dayOfWeek;
17165  }
17166  return $this->startOfDay()->modify('last ' . static::$days[$dayOfWeek]);
17167  }
17168  public function firstOfMonth($dayOfWeek = null)
17169  {
17170  $this->startOfDay();
17171  if ($dayOfWeek === null) {
17172  return $this->day(1);
17173  }
17174  return $this->modify('first ' . static::$days[$dayOfWeek] . ' of ' . $this->format('F') . ' ' . $this->year);
17175  }
17176  public function lastOfMonth($dayOfWeek = null)
17177  {
17178  $this->startOfDay();
17179  if ($dayOfWeek === null) {
17180  return $this->day($this->daysInMonth);
17181  }
17182  return $this->modify('last ' . static::$days[$dayOfWeek] . ' of ' . $this->format('F') . ' ' . $this->year);
17183  }
17184  public function nthOfMonth($nth, $dayOfWeek)
17185  {
17186  $dt = $this->copy()->firstOfMonth();
17187  $check = $dt->format('Y-m');
17188  $dt->modify('+' . $nth . ' ' . static::$days[$dayOfWeek]);
17189  return $dt->format('Y-m') === $check ? $this->modify($dt) : false;
17190  }
17191  public function firstOfQuarter($dayOfWeek = null)
17192  {
17193  return $this->day(1)->month($this->quarter * 3 - 2)->firstOfMonth($dayOfWeek);
17194  }
17195  public function lastOfQuarter($dayOfWeek = null)
17196  {
17197  return $this->day(1)->month($this->quarter * 3)->lastOfMonth($dayOfWeek);
17198  }
17199  public function nthOfQuarter($nth, $dayOfWeek)
17200  {
17201  $dt = $this->copy()->day(1)->month($this->quarter * 3);
17202  $last_month = $dt->month;
17203  $year = $dt->year;
17204  $dt->firstOfQuarter()->modify('+' . $nth . ' ' . static::$days[$dayOfWeek]);
17205  return $last_month < $dt->month || $year !== $dt->year ? false : $this->modify($dt);
17206  }
17207  public function firstOfYear($dayOfWeek = null)
17208  {
17209  return $this->month(1)->firstOfMonth($dayOfWeek);
17210  }
17211  public function lastOfYear($dayOfWeek = null)
17212  {
17213  return $this->month(static::MONTHS_PER_YEAR)->lastOfMonth($dayOfWeek);
17214  }
17215  public function nthOfYear($nth, $dayOfWeek)
17216  {
17217  $dt = $this->copy()->firstOfYear()->modify('+' . $nth . ' ' . static::$days[$dayOfWeek]);
17218  return $this->year == $dt->year ? $this->modify($dt) : false;
17219  }
17220  public function average(Carbon $dt = null)
17221  {
17222  $dt = $dt === null ? static::now($this->tz) : $dt;
17223  return $this->addSeconds((int) ($this->diffInSeconds($dt, false) / 2));
17224  }
17225  public function isBirthday(Carbon $dt)
17226  {
17227  return $this->format('md') === $dt->format('md');
17228  }
17229 }
17230 namespace App\Providers;
17231 
17233 class AppServiceProvider extends ServiceProvider
17234 {
17235  public function boot()
17236  {
17237  }
17238  public function register()
17239  {
17240  $this->app->bind('Illuminate\\Contracts\\Auth\\Registrar', 'App\\Services\\Registrar');
17241  }
17242 }
17243 namespace App\Providers;
17244 
17247 class BusServiceProvider extends ServiceProvider
17248 {
17249  public function boot(Dispatcher $dispatcher)
17250  {
17251  $dispatcher->mapUsing(function ($command) {
17252  return Dispatcher::simpleMapping($command, 'App\\Commands', 'App\\Handlers\\Commands');
17253  });
17254  }
17255  public function register()
17256  {
17257  }
17258 }
17259 namespace App\Providers;
17260 
17262 class ConfigServiceProvider extends ServiceProvider
17263 {
17264  public function register()
17265  {
17266  config(array());
17267  }
17268 }
17269 namespace App\Providers;
17270 
17271 use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
17273 class EventServiceProvider extends ServiceProvider
17274 {
17275  protected $listen = array('event.name' => array('EventListener'));
17276  public function boot(DispatcherContract $events)
17277  {
17278  parent::boot($events);
17279  }
17280 }
17281 namespace App\Providers;
17282 
17285 class RouteServiceProvider extends ServiceProvider
17286 {
17287  protected $namespace = 'App\\Http\\Controllers';
17288  public function boot(Router $router)
17289  {
17290  parent::boot($router);
17291  }
17292  public function map(Router $router)
17293  {
17294  $router->group(array('namespace' => $this->namespace), function ($router) {
17295  require app_path('Http/routes.php');
17296  });
17297  }
17298 }
input($key, $default=null)
Definition: compiled.php:7228
makeDisposition($disposition, $filename, $filenameFallback= '')
Definition: compiled.php:14812
static except($array, $keys)
Definition: compiled.php:5448
duplicate(array $query=null, array $request=null, array $attributes=null, array $cookies=null, array $files=null, array $server=null)
Definition: compiled.php:2686
afterBootstrapping($bootstrapper, Closure $callback)
Definition: compiled.php:1326
static hydrateRaw($query, $bindings=array(), $connection=null)
Definition: compiled.php:9450
set($key, $value=null)
Definition: compiled.php:6141
hasMany($related, $foreignKey=null, $localKey=null)
Definition: compiled.php:9592
boot(Dispatcher $dispatcher)
Definition: compiled.php:17249
notice($message, array $context=array())
Definition: compiled.php:12342
splice($offset, $length=0, $replacement=array())
Definition: compiled.php:11648
convertToControllerAction($action)
Definition: compiled.php:6970
filter(callable $callback)
Definition: compiled.php:11441
tag($abstracts, $tags)
Definition: compiled.php:858
dispatchNow($command, Closure $afterResolving=null)
Definition: compiled.php:8886
static __callStatic($method, $parameters)
Definition: compiled.php:10596
diffInDays(Carbon $dt=null, $abs=true)
Definition: compiled.php:16984
static translator()
Definition: compiled.php:16630
replaceRoutableParameters($parameters=array())
Definition: compiled.php:8652
missingMethod($parameters=array())
Definition: compiled.php:8351
Bo geo path
Definition: d3.min.js:4
static setRouter(Router $router)
Definition: compiled.php:8343
singleton($abstract, $concrete=null)
Definition: compiled.php:818
static firstOrCreate(array $attributes)
Definition: compiled.php:9472
setDispatcher(Dispatcher $events)
Definition: compiled.php:627
isHandling($level)
Definition: compiled.php:12317
header($key=null, $default=null)
Definition: compiled.php:2292
static saved($callback, $priority=0)
Definition: compiled.php:9702
transform(callable $callback)
Definition: compiled.php:11671
sortByDesc($callback, $options=SORT_REGULAR)
Definition: compiled.php:11644
addFallthroughRoute($controller, $uri)
Definition: compiled.php:6863
static create($content= '', $status=200, $headers=array())
Definition: compiled.php:14220
$_SERVER['f']
dispatch($command, Closure $afterResolving=null)
Definition: compiled.php:8878
subMonthsNoOverflow($value)
Definition: compiled.php:16870
callQueueMethodOnHandler($class, $method, $arguments)
Definition: compiled.php:9260
setCookieJar(CookieJar $cookie)
Definition: compiled.php:619
bind($abstract, $concrete=null, $shared=false)
beforeFilter($filter, array $options=array())
Definition: compiled.php:8272
subDays($value)
Definition: compiled.php:16886
filterFailsMethod($filter, $request, $method)
Definition: compiled.php:8453
handle(SymfonyRequest $request, $type=self::MASTER_REQUEST, $catch=true)
Definition: compiled.php:1540
callWithinStack($instance, $route, $request, $method)
Definition: compiled.php:8391
__construct(Container $container)
Definition: compiled.php:8987
retrieveByCredentials(array $credentials)
Definition: compiled.php:716
static setLocale($locale)
Definition: compiled.php:16651
callClass($target, array $parameters=array(), $defaultMethod=null)
Definition: compiled.php:963
make($abstract, $parameters=array())
__construct($file, $relativePath, $relativePathname)
Definition: compiled.php:15069
renderException($request, Exception $e)
Definition: compiled.php:1992
subMonthNoOverflow($value=1)
Definition: compiled.php:16866
getOriginal($key=null, $default=null)
Definition: compiled.php:10428
first($key=null, $format=null)
Definition: compiled.php:13471
shouldRecompile($manifest, $providers)
Definition: compiled.php:6530
morphedByMany($related, $name, $table=null, $foreignKey=null, $otherKey=null)
Definition: compiled.php:9638
isEmpty()
Definition: Functions.php:2037
addWeeks($value)
Definition: compiled.php:16906
emerg($message, array $context=array())
Definition: compiled.php:12374
diffForHumans(Carbon $other=null, $absolute=false)
Definition: compiled.php:17048
attempting($callback)
Definition: compiled.php:534
string url
Definition: setup.py:39
contains($key, $value=null)
Definition: compiled.php:11416
fireAppCallbacks(array $callbacks)
Definition: compiled.php:1596
Bo locale
Definition: d3.min.js:3
static explodeArrayFilters(array $filters)
Definition: compiled.php:7436
addWeekdays($value)
Definition: compiled.php:16890
setPdoForType(Connection $connection, $type=null)
Definition: compiled.php:10688
subHour($value=1)
Definition: compiled.php:16930
check(array $routes, $request, $includingMethod=true)
Definition: compiled.php:7781
addHours($value)
Definition: compiled.php:16922
crit($message, array $context=array())
Definition: compiled.php:12362
warning($message, array $context=array())
Definition: compiled.php:12055
marshal($command, ArrayAccess $source, array $extras=array())
Definition: compiled.php:8854
static load($path, $file= '.env')
Definition: Dotenv.php:18
setSession(SessionInterface $session)
Definition: compiled.php:2849
useFiles($path, $level= 'debug')
Definition: compiled.php:12084
configureHandlers(Application $app, Writer $log)
Definition: compiled.php:1714
put($key, $value=null)
Definition: compiled.php:11106
static set(&$array, $key, $value)
Definition: compiled.php:5560
extractAlias(array $definition)
Definition: compiled.php:882
rebinding($abstract, Closure $callback)
Definition: compiled.php:886
formatLocalized($format)
Definition: compiled.php:16656
isJson()
Definition: Functions.php:2080
updateRememberToken(UserContract $user, $token)
Definition: compiled.php:711
month($value)
Definition: compiled.php:16560
morphMany($related, $name, $type=null, $id=null, $localKey=null)
Definition: compiled.php:9606
static formatGroupPrefix($new, $old)
Definition: compiled.php:6914
if(0!==$parseFail) if(0!==$ppFail) $count
Definition: run.php:174
addYear($value=1)
Definition: compiled.php:16826
$app
Definition: app.php:14
static createFromFormat($format, $time, $tz=null)
Definition: compiled.php:16460
get($key, $default=null, $deep=false)
Definition: compiled.php:2824
__construct(array $parameters=array())
Definition: compiled.php:3365
dispatchFrom($command, ArrayAccess $source, array $extras=array())
Definition: compiled.php:8846
query($key=null, $default=null)
Definition: compiled.php:2260
static $testNow
Definition: compiled.php:16373
static getInstance(array $aliases=array())
Definition: compiled.php:6417
deleteDirectory($directory, $preserve=false)
Definition: compiled.php:6383
once(array $credentials=array())
Definition: compiled.php:467
regex($regex)
Definition: analyze.php:23
basic($field= 'email')
Definition: compiled.php:479
static singular($value)
Definition: compiled.php:5700
yieldContent($section, $default= '')
Definition: compiled.php:13282
static on($connection=null)
Definition: compiled.php:9500
firstOfQuarter($dayOfWeek=null)
Definition: compiled.php:17191
addDependencyForCallParameter(ReflectionParameter $parameter, array &$parameters, &$dependencies)
Definition: compiled.php:952
next($dayOfWeek=null)
Definition: compiled.php:17154
addExtension($extension, $engine, $resolver=null)
Definition: compiled.php:13326
screamAt($levels, $replace=false)
Definition: compiled.php:5883
$arguments
Definition: run.php:27
any()
Definition: Functions.php:18
removeFilter($removing, $current)
Definition: compiled.php:8321
commandShouldBeQueued($command)
Definition: compiled.php:8899
pushProcessor($callback)
Definition: compiled.php:12221
updateGroupStack(array $attributes)
Definition: compiled.php:6884
__construct(array $query=array(), array $request=array(), array $attributes=array(), array $cookies=array(), array $files=array(), array $server=array(), $content=null)
Definition: compiled.php:2574
__construct($name, array $handlers=array(), array $processors=array())
Definition: compiled.php:12196
write($level, $message, array $context=array())
Definition: compiled.php:12075
alias($view, $alias)
Definition: compiled.php:13110
getRouteRoot($route, $domain)
Definition: compiled.php:8704
onceBasic($field= 'email')
Definition: compiled.php:489
diffInYears(Carbon $dt=null, $abs=true)
Definition: compiled.php:16970
gatherRouteMiddlewares(Route $route)
Definition: compiled.php:7019
__construct($time=null, $tz=null)
Definition: compiled.php:16389
resource($name, $controller, array $options=array())
Definition: compiled.php:6874
once()
Definition: Functions.php:2300
registerClosureFilter(Closure $filter)
Definition: compiled.php:8293
alert($message, array $context=array())
Definition: compiled.php:12370
__construct($storageKey= '_sf2_meta', $updateThreshold=0)
Definition: compiled.php:3875
subMonths($value)
Definition: compiled.php:16850
static getLocale()
Definition: compiled.php:16647
diffInWeekdays(Carbon $dt=null, $abs=true)
Definition: compiled.php:17014
static is($pattern, $value)
Definition: compiled.php:5636
configureSingleHandler(Application $app, Writer $log)
Definition: compiled.php:1719
static createFromTime($hour=null, $minute=null, $second=null, $tz=null)
Definition: compiled.php:16456
share(Closure $closure)
Definition: compiled.php:822
where($column, $operator=null, $value=null, $boolean= 'and')
Definition: Builder.php:514
where($name, $expression=null)
Definition: compiled.php:7594
subWeeks($value)
Definition: compiled.php:16918
addInfo($message, array $context=array())
Definition: compiled.php:12271
decrement($column, $amount=1)
Definition: compiled.php:9769
when($pattern, $name, $methods=null)
Definition: compiled.php:7080
resolving($abstract, Closure $callback=null)
Definition: compiled.php:1090
registerDeferredProvider($provider, $service=null)
Definition: compiled.php:1483
log($level, $message, array $context=array())
Definition: compiled.php:12071
make($value, array $options=array())
Definition: compiled.php:4988
registerInspected($route, $controller, $method, &$names)
Definition: compiled.php:6857
run(Request $request)
Definition: compiled.php:7342
matches(Request $request, $includingMethod=true)
Definition: compiled.php:7381
static safeCreateDateTimeZone($object)
Definition: compiled.php:16375
setRoutes(RouteCollection $routes)
Definition: compiled.php:8766
createRememberTokenIfDoesntExist(UserContract $user)
Definition: compiled.php:605
bindIf($abstract, $concrete=null, $shared=false)
Definition: compiled.php:812
static has($array, $key)
Definition: compiled.php:5520
getMappingSegment($className, $segment)
Definition: compiled.php:8949
bind(Request $request)
Definition: compiled.php:7507
handle($level, $message, $file= 'unknown', $line=0, $context=array())
Definition: compiled.php:6090
callRouteBefore($route, $request)
Definition: compiled.php:7139
matches(Route $route, Request $request)
Definition: compiled.php:9045
static setLogger(LoggerInterface $logger, $channel= 'deprecation')
Definition: compiled.php:6071
log($level, $message, array $context=array())
Definition: compiled.php:12327
useSyslog($name= 'laravel', $level= 'debug')
Definition: compiled.php:12094
getDependencies($parameters, array $primitives=array())
Definition: compiled.php:1046
handleError($type, $message, $file, $line, array $context)
Definition: compiled.php:5904
copyDirectory($directory, $destination, $options=null)
Definition: compiled.php:6358
static forget(&$array, $keys)
Definition: compiled.php:5489
instance($abstract, $instance)
Definition: compiled.php:845
static findOrNew($id, $columns=array('*'))
Definition: compiled.php:9520
getAlpha($key, $default= '', $deep=false)
Definition: compiled.php:3436
addAdapter(AdapterInterface $adapter, $priority=0)
Definition: compiled.php:16088
d d d prototype close
Definition: bootstrap.min.js:6
Bo ya ya ya ya ya ya ya ya ya ya ya ya filter
Definition: d3.min.js:3
terminating(Closure $callback)
Definition: compiled.php:1617
addClassEvent($view, $class, $prefix, $priority=null)
Definition: compiled.php:13198
afterResolvingCallback(Closure $callback)
Definition: compiled.php:1115
beforeBootstrapping($bootstrapper, Closure $callback)
Definition: compiled.php:1322
filter($name, $callback)
Definition: compiled.php:7069
cleanFilterParameters(array $parameters)
Definition: compiled.php:7207
__construct($path, $flags, $ignoreUnreadableDirs=false)
Definition: compiled.php:15427
diffInWeeks(Carbon $dt=null, $abs=true)
Definition: compiled.php:16980
$collection
Definition: validpattern.php:6
handle($request, Closure $next)
Definition: compiled.php:2459
__construct(MonologLogger $monolog, Dispatcher $dispatcher=null)
Definition: compiled.php:12032
static instance(DateTime $dt)
Definition: compiled.php:16405
detect(Closure $callback, $consoleArgs=null)
Definition: compiled.php:1670
error($message, array $context=array())
Definition: compiled.php:12358
middleware($name, $class)
Definition: compiled.php:7064
asset($path, $secure=null)
Definition: compiled.php:8577
setFilenameFormat($filenameFormat, $dateFormat)
Definition: compiled.php:12596
__call($method, $parameters)
Definition: compiled.php:13705
setEscapedContentTags($openTag, $closeTag)
Definition: compiled.php:14117
__construct($pattern, $options= '', $delimiter=null)
Definition: compiled.php:15121
Vl rc scale Bo Bo json
Definition: d3.min.js:5
static first($array, callable $callback, $default=null)
Definition: compiled.php:5468
addCritical($message, array $context=array())
Definition: compiled.php:12287
lastOfQuarter($dayOfWeek=null)
Definition: compiled.php:17195
__construct(SessionManager $manager)
Definition: compiled.php:10862
addWeekday($value=1)
Definition: compiled.php:16894
static setToStringFormat($format)
Definition: compiled.php:16667
setTimezone($value)
Definition: compiled.php:16602
addRequirements(array $requirements)
Definition: compiled.php:8194
filterApplies($filter, $request, $method)
Definition: compiled.php:8444
static unguarded(callable $callback)
Definition: compiled.php:10122
methodExcludedByOptions($method, array $options)
Definition: compiled.php:8409
static saving($callback, $priority=0)
Definition: compiled.php:9698
Bo dispatch
Definition: d3.min.js:3
make($abstract, $parameters=array())
Definition: compiled.php:1495
setRawAttributes(array $attributes, $sync=false)
Definition: compiled.php:10421
__construct(array $parameters=array())
Definition: compiled.php:3482
sort(callable $callback)
Definition: compiled.php:11623
parameter($name, $default=null)
Definition: compiled.php:7464
static dot($array, $prepend= '')
Definition: compiled.php:5436
nest($key, $view, array $data=array())
Definition: compiled.php:13632
old($key=null, $default=null)
Definition: compiled.php:2300
getParameter($name, $default=null)
Definition: compiled.php:7460
getRoutable($controller, $prefix)
Definition: compiled.php:8480
static getLevelName($level)
Definition: compiled.php:12303
getClosure($abstract, $concrete)
Definition: compiled.php:801
isBuildable($concrete, $abstract)
Definition: compiled.php:1168
fireResolvingCallbacks($abstract, $object)
Definition: compiled.php:1136
secure($path, $parameters=array())
Definition: compiled.php:8573
push($event, $payload=array())
Definition: compiled.php:9130
setUserResolver(Closure $callback)
Definition: compiled.php:2412
postRegister(Request $request)
Definition: compiled.php:2014
morphOne($related, $name, $type=null, $id=null, $localKey=null)
Definition: compiled.php:9556
keyParametersByArgument(array $dependencies, array $parameters)
Definition: compiled.php:1080
hasOne($related, $foreignKey=null, $localKey=null)
Definition: compiled.php:9549
static hydrate(array $items, $connection=null)
Definition: compiled.php:9442
extend($abstract, Closure $closure)
Definition: compiled.php:836
call($instance, $route, $method)
Definition: compiled.php:8413
info($message, array $context=array())
Definition: compiled.php:12338
addDay($value=1)
Definition: compiled.php:16878
addDebug($message, array $context=array())
Definition: compiled.php:12267
maps(array $commands)
Definition: compiled.php:8957
seed($class= 'DatabaseSeeder')
whereArray(array $wheres)
Definition: compiled.php:7605
postEmail(Request $request)
Definition: compiled.php:2071
timestamp($value)
Definition: compiled.php:16589
performBinding($key, $value, $route)
Definition: compiled.php:7040
setFinder(ViewFinderInterface $finder)
Definition: compiled.php:13347
static startsWith($haystack, $needles)
Definition: compiled.php:5724
retrieveByToken($identifier, $token)
Definition: compiled.php:706
addNamespace($namespace, $hints)
Definition: compiled.php:12998
Bo Bo Bo Bo shuffle
Definition: d3.min.js:3
addCookieToResponse(Response $response, SessionInterface $session)
Definition: compiled.php:10916
makeDirectory($path, $mode=493, $recursive=false, $force=false)
Definition: compiled.php:6351
Bo Bo Bo Bo Bo Bo Bo Bo Bo keys
Definition: d3.min.js:3
needsRehash($hashedValue, array $options=array())
Definition: compiled.php:5001
increment($column, $amount=1)
Definition: compiled.php:9765
__construct(ApplicationContract $app, Filesystem $files, $manifestPath)
Definition: compiled.php:6480
setRequestOnHandler(Request $request)
Definition: compiled.php:11234
__construct($seedFile=null, LoggerInterface $logger=null)
Definition: compiled.php:15005
subSeconds($value)
Definition: compiled.php:16966
static length($value)
Definition: compiled.php:5645
static updating($callback, $priority=0)
Definition: compiled.php:9706
inject($section, $content)
Definition: compiled.php:13247
__construct(ContainerContract $container=null)
Definition: compiled.php:9107
prependNamespace($namespace, $hints)
Definition: compiled.php:13322
static find($id, $columns=array('*'))
Definition: compiled.php:9516
matchToKeys(array $matches)
Definition: compiled.php:7531
subWeekday($value=1)
Definition: compiled.php:16898
withErrors($provider)
Definition: compiled.php:13636
make($abstract, $parameters=array())
Definition: compiled.php:972
static limit($value, $limit=100, $end= '...')
Definition: compiled.php:5649
queueRecallerCookie(UserContract $user)
Definition: compiled.php:572
__construct($format=null, $dateFormat=null, $allowInlineLineBreaks=false, $ignoreEmptyContextAndExtra=false)
Definition: compiled.php:12778
getRootUrl($scheme, $root=null)
Definition: compiled.php:8729
addContextualBinding($concrete, $abstract, $implementation)
Definition: compiled.php:808
var $c
Definition: d3.min.js:4
patch($uri, $action)
Definition: compiled.php:6816
$_FILES['g']
addMinutes($value)
Definition: compiled.php:16938
static add($array, $key, $value)
Definition: compiled.php:5416
createConnection($driver, PDO $connection, $database, $prefix= '', array $config=array())
Definition: compiled.php:10819
fresh(array $with=array())
Definition: compiled.php:9527
Bo ya ya ya ya ya ya ya ya ya ya ya ya ya ya ya ya call
Definition: d3.min.js:3
insertAndSetId(Builder $query, $attributes)
Definition: compiled.php:9869
resolving($abstract, Closure $callback=null)
runCallable(Request $request)
Definition: compiled.php:7357
Bo Bo Bo Bo Bo Bo Bo Bo Bo Bo Bo Bo merge
Definition: d3.min.js:3
static closeOutputBuffers($targetLevel, $flush)
Definition: compiled.php:14630
ignoreDotFiles($ignoreDotFiles)
Definition: compiled.php:16178
slice($offset, $length=null, $preserveKeys=false)
Definition: compiled.php:11611
build($concrete, $parameters=array())
Definition: compiled.php:1024
__construct(Filesystem $files, $cachePath)
Definition: compiled.php:13804
replaceNamedParameters($path, &$parameters)
Definition: compiled.php:8634
__call($method, $parameters)
Definition: compiled.php:13412
subHours($value)
Definition: compiled.php:16934
getBoolean($key, $default=false, $deep=false)
Definition: compiled.php:3452
static words($value, $words=100, $end= '...')
Definition: compiled.php:5660
$diff
Definition: example.php:28
cookie($key=null, $default=null)
Definition: compiled.php:2268
static tomorrow($tz=null)
Definition: compiled.php:16421
createRoute($methods, $uri, $action)
Definition: compiled.php:6933
static yesterday($tz=null)
Definition: compiled.php:16425
match($methods, $uri, $action)
Definition: compiled.php:6833
function factory
Definition: jquery.js:15
second($value)
Definition: compiled.php:16580
useDailyFiles($path, $days=0, $level= 'debug')
Definition: compiled.php:12089
registerLoadEvents($provider, array $events)
Definition: compiled.php:6500
inflectSegment($command, $segment)
Definition: compiled.php:8939
route($name, $parameters=array(), $absolute=true)
Definition: compiled.php:8609
fireAttemptEvent(array $credentials, $remember, $login)
Definition: compiled.php:527
setDeferredServices(array $services)
Definition: compiled.php:1632
parseFilter($filter, array $options)
Definition: compiled.php:8280
setRequest(Request $request)
Definition: compiled.php:656
removeFromOldFlashData(array $keys)
Definition: compiled.php:11147
static deleted($callback, $priority=0)
Definition: compiled.php:9726
jl Io Io rc rc rc seconds rc minute
Definition: d3.min.js:5
fillableFromArray(array $attributes)
Definition: compiled.php:9422
replace(array $input)
Definition: compiled.php:2334
static currentPageResolver(Closure $resolver)
Definition: compiled.php:5151
if(!file_exists($kmyacc)) $options
static deleting($callback, $priority=0)
Definition: compiled.php:9722
idleTimeout options
afterResolving($abstract, Closure $callback=null)
Definition: compiled.php:1098
handleError($level, $message, $file= '', $line=0, $context=array())
Definition: compiled.php:1756
addMinute($value=1)
Definition: compiled.php:16942
with($key, $value=null)
Definition: compiled.php:13623
setRequest(Request $request)
Definition: compiled.php:8760
diffInHours(Carbon $dt=null, $abs=true)
Definition: compiled.php:17026
getInitialSlice(Closure $destination)
Definition: compiled.php:9024
static handleFatalError(array $error=null)
Definition: compiled.php:5999
getUserByRecaller($recaller)
Definition: compiled.php:440
shared($key, $default=null)
Definition: compiled.php:13367
isRoutable(ReflectionMethod $method)
Definition: compiled.php:8496
each(callable $callback)
Definition: compiled.php:11432
filterSupportsMethod($filter, $method)
Definition: compiled.php:7182
middleware($middleware, array $options=array())
Definition: compiled.php:8268
$_REQUEST['h']
Bo Bo behavior Bo touches
Definition: d3.min.js:3
static pathsToPublish($provider=null, $group=null)
Definition: compiled.php:4422
__construct(\Iterator $iterator, array $directories)
Definition: compiled.php:15400
__construct(array $attributes=array())
Definition: compiled.php:9346
model($key, $class, Closure $callback=null)
Definition: compiled.php:7094
incrementOrDecrementAttributeValue($column, $amount, $method)
Definition: compiled.php:9782
__isset($name)
Definition: compiled.php:16514
ne(Carbon $dt)
Definition: compiled.php:16743
extend($name, callable $resolver)
Definition: compiled.php:10714
resources(array $resources)
Definition: compiled.php:6868
static explodeFilters($filters)
Definition: compiled.php:7429
json($key=null, $default=null)
Definition: compiled.php:2338
static endsWith($haystack, $needles)
Definition: compiled.php:5622
segment($index, $default=null)
Definition: compiled.php:2168
static pluck($array, $value, $key=null)
Definition: compiled.php:5540
controller($uri, $controller, $names=array())
Definition: compiled.php:6843
between(Carbon $dt1, Carbon $dt2, $equal=true)
Definition: compiled.php:16763
fatalExceptionFromError(array $error, $traceOffset=null)
Definition: compiled.php:1785
update(array $attributes=array())
Definition: compiled.php:9787
offsetSet($offset, $value)
Definition: compiled.php:2435
put($path, $contents, $lock=false)
Definition: compiled.php:6255
initialize(array $query=array(), array $request=array(), array $attributes=array(), array $cookies=array(), array $files=array(), array $server=array(), $content=null)
Definition: compiled.php:2578
fireModelEvent($event, $halt=true)
Definition: compiled.php:9887
error($message, array $context=array())
Definition: compiled.php:12051
__construct(RouteCollection $routes, Request $request)
Definition: compiled.php:8543
morphTo($name=null, $type=null, $id=null)
Definition: compiled.php:9578
addRecord($level, $message, array $context=array())
Definition: compiled.php:12239
throwAt($levels, $replace=false)
Definition: compiled.php:5854
minute($value)
Definition: compiled.php:16575
filterFailsOn($filter, $request, $method)
Definition: compiled.php:8457
static title($value)
Definition: compiled.php:5696
__set($key, $value)
Definition: compiled.php:13693
static equals($knownString, $userInput)
Definition: compiled.php:14954
nthOfQuarter($nth, $dayOfWeek)
Definition: compiled.php:17199
static getTranslator()
Definition: compiled.php:16639
buildClassEventCallback($class, $prefix)
Definition: compiled.php:13213
static divide($array)
Definition: compiled.php:5432
runRouteWithinStack(Route $route, Request $request)
Definition: compiled.php:7012
static mergeGroup($new, $old)
Definition: compiled.php:6895
bindHostParameters(Request $request, $parameters)
Definition: compiled.php:7526
static setTrustedHosts(array $hostPatterns)
Definition: compiled.php:2773
terminate($request, $response)
Definition: compiled.php:1939
set($key, $values, $replace=true)
Definition: compiled.php:3651
getStringParameters(array $parameters)
Definition: compiled.php:8673
getPreferredLanguage(array $locales=null)
Definition: compiled.php:3136
static createFromTimestamp($timestamp, $tz=null)
Definition: compiled.php:16473
static registerModelEvent($event, $callback, $priority=0)
Definition: compiled.php:9740
Bo Bo timer Bo round
Definition: d3.min.js:3
bindShared($abstract, Closure $closure)
Definition: compiled.php:832
year($value)
Definition: compiled.php:16555
addSecond($value=1)
Definition: compiled.php:16958
fireLoginEvent($user, $remember=false)
Definition: compiled.php:550
addMonths($value)
Definition: compiled.php:16838
static firstOrNew(array $attributes)
Definition: compiled.php:9479
runController(Request $request)
Definition: compiled.php:7362
attempt(array $credentials=array(), $remember=false, $login=true)
Definition: compiled.php:511
save(array $options=array())
Definition: compiled.php:9809
static contains($haystack, $needles)
Definition: compiled.php:5613
Bo touch
Definition: d3.min.js:3
invalidate($lifetime=null)
Definition: compiled.php:11037
resolveNonClass(ReflectionParameter $parameter)
Definition: compiled.php:1061
refreshRememberToken(UserContract $user)
Definition: compiled.php:600
subWeek($value=1)
Definition: compiled.php:16914
function e version
Definition: nv.d3.min.js:1
validateCredentials(UserContract $user, array $credentials)
Definition: compiled.php:726
chunk($size, $preserveKeys=false)
Definition: compiled.php:11615
diffInHoursFiltered(Closure $callback, Carbon $dt=null, $abs=true)
Definition: compiled.php:16993
pull($key, $default=null)
Definition: compiled.php:11088
firstOfYear($dayOfWeek=null)
Definition: compiled.php:17207
addDays($value)
Definition: compiled.php:16874
diffInMinutes(Carbon $dt=null, $abs=true)
Definition: compiled.php:17030
defaults($key, $value)
Definition: compiled.php:7589
scopeAt($levels, $replace=false)
Definition: compiled.php:5865
static createFromBase($request)
buildContentFiltering(Command $command, array $contains, $not=false)
Definition: compiled.php:15924
static setEventDispatcher(Dispatcher $dispatcher)
Definition: compiled.php:10527
fireLogEvent($level, $message, array $context=array())
Definition: compiled.php:12110
group(array $attributes, Closure $callback)
Definition: compiled.php:6878
__construct(Factory $factory, EngineInterface $engine, $view, $path, $data=array())
Definition: compiled.php:13579
static setConnectionResolver(Resolver $resolver)
Definition: compiled.php:10515
Date now(Date.now=function(){return+new Date})
getMethodData(ReflectionMethod $method, $prefix)
Definition: compiled.php:8503
$lock
static createFromBase(SymfonyRequest $request)
Definition: compiled.php:2373
getRouteForMethods($request, array $methods)
Definition: compiled.php:7768
getDate($key,\DateTime $default=null)
Definition: compiled.php:3680
static creating($callback, $priority=0)
Definition: compiled.php:9714
addViewEvent($view, $callback, $prefix= 'composing: ', $priority=null)
Definition: compiled.php:13188
__construct(Container $container, Closure $queueResolver=null)
Definition: compiled.php:8836
static fetch($array, $key)
Definition: compiled.php:5455
call($callback, array $parameters=array(), $defaultMethod=null)
Definition: compiled.php:919
removeCookie($name, $path= '/', $domain=null)
Definition: compiled.php:14777
firstOfMonth($dayOfWeek=null)
Definition: compiled.php:17168
mergeGroupAttributesIntoRoute($route)
Definition: compiled.php:6958
getAlnum($key, $default= '', $deep=false)
Definition: compiled.php:3440
__construct($filename, $maxFiles=0, $level=Logger::DEBUG, $bubble=true, $filePermission=null, $useLocking=false)
Definition: compiled.php:12580
collectGarbage(SessionInterface $session)
Definition: compiled.php:10905
static finish($value, $cap)
Definition: compiled.php:5631
afterResolving($abstract, Closure $callback=null)
handleException(\Exception $exception, array $error=null)
Definition: compiled.php:5962
configureSyslogHandler(Application $app, Writer $log)
Definition: compiled.php:1727
static setTranslator(TranslatorInterface $translator)
Definition: compiled.php:16643
static snake($value, $delimiter= '_')
Definition: compiled.php:5713
login(UserContract $user, $remember=false)
Definition: compiled.php:540
static minValue()
Definition: compiled.php:16433
getOldInput($key=null, $default=null)
Definition: compiled.php:11097
resolveSubscriber($subscriber)
Definition: compiled.php:9141
debug($message, array $context=array())
Definition: compiled.php:12334
warn($message, array $context=array())
Definition: compiled.php:12346
static ascii($value)
Definition: compiled.php:5602
setDateTime($year, $month, $day, $hour, $minute, $second=0)
Definition: compiled.php:16585
subYear($value=1)
Definition: compiled.php:16830
configureDailyHandler(Application $app, Writer $log)
Definition: compiled.php:1723
addGlobalFilter($filter, $callback)
Definition: compiled.php:7056
__construct($stream, $level=Logger::DEBUG, $bubble=true, $filePermission=null, $useLocking=false)
Definition: compiled.php:12518
getParameterValueForCommand($command, ArrayAccess $source, ReflectionParameter $parameter, array $extras=array())
Definition: compiled.php:8865
bindIf($abstract, $concrete=null, $shared=false)
static setTrustedProxies(array $proxies)
Definition: compiled.php:2765
setSessionResolver(callable $sessionResolver)
Definition: compiled.php:8781
fireCallbackArray($object, array $callbacks)
Definition: compiled.php:1153
static simpleMapping($command, $commandNamespace, $handlerNamespace)
Definition: compiled.php:8965
callAction($method, $parameters)
Definition: compiled.php:8347
__call($method, $parameters)
Definition: compiled.php:8355
subDay($value=1)
Definition: compiled.php:16882
afterLoadingEnvironment(Closure $callback)
Definition: compiled.php:1318
debug($message, array $context=array())
Definition: compiled.php:12067
static studly($value)
Definition: compiled.php:5733
alias($abstract, $alias)
Definition: compiled.php:878
storeCurrentUrl(Request $request, $session)
Definition: compiled.php:10899
marshalFromArray($command, array $array)
Definition: compiled.php:8850
emergency($message, array $context=array())
Definition: compiled.php:12039
before($instance, $route, $request, $method)
Definition: compiled.php:8418
reduce(callable $callback, $initial=null)
Definition: compiled.php:11579
getDigits($key, $default= '', $deep=false)
Definition: compiled.php:3444
createClassCallable($listener, $container)
Definition: compiled.php:9221
writeLog($level, $message, $context)
Definition: compiled.php:12079
critical($message, array $context=array())
Definition: compiled.php:12047
gte(Carbon $dt)
Definition: compiled.php:16751
lt(Carbon $dt)
Definition: compiled.php:16755
Bo ya ya ya ya ya ya ya ya ya remove
Definition: d3.min.js:3
setReconnector(callable $reconnector)
Definition: Connection.php:862
err($message, array $context=array())
Definition: compiled.php:12354
hasManyThrough($related, $through, $firstKey=null, $secondKey=null)
Definition: compiled.php:9599
static currentPathResolver(Closure $resolver)
Definition: compiled.php:5140
addSeconds($value)
Definition: compiled.php:16954
static addGlobalScope(ScopeInterface $scope)
Definition: compiled.php:9374
composers(array $composers)
Definition: compiled.php:13172
controllers(array $controllers)
Definition: compiled.php:6837
patternsByMethod($method, $filters)
Definition: compiled.php:7171
duplicate(array $query=null, array $request=null, array $attributes=null, array $cookies=null, array $files=null, array $server=null)
Definition: compiled.php:2384
__construct($staticPrefix, $regex, array $tokens, array $pathVariables, $hostRegex=null, array $hostTokens=array(), array $hostVariables=array(), array $variables=array())
Definition: compiled.php:7831
listen($events, $listener, $priority=0)
Definition: compiled.php:9111
renderEach($view, $data, $iterator, $empty= 'raw|')
Definition: compiled.php:13123
static camel($value)
Definition: compiled.php:5606
action($action, $parameters=array(), $absolute=true)
Definition: compiled.php:8717
transform($messages, $format, $messageKey)
Definition: compiled.php:13493
format($default= 'html')
Definition: compiled.php:2364
initializeRequest(FormRequest $form, Request $current)
Definition: compiled.php:4823
$output
static resolveCurrentPath($default= '/')
Definition: compiled.php:5133
function $i(n)
Definition: d3.min.js:2
useStoragePathForOptimizations($value=true)
Definition: compiled.php:1591
static setInstance(ContainerContract $container)
Definition: compiled.php:1203
cloneArgumentsForQueueing(array $arguments)
Definition: compiled.php:9254
check($value, $hashedValue, array $options=array())
Definition: compiled.php:4997
diffInWeekendDays(Carbon $dt=null, $abs=true)
Definition: compiled.php:17020
$_GET['d']
static updateOrCreate(array $attributes, array $values=array())
Definition: compiled.php:9486
trait RouteDependencyResolverTrait
Definition: compiled.php:6741
static addVCSPattern($pattern)
Definition: compiled.php:16196
addEmergency($message, array $context=array())
Definition: compiled.php:12295
assignAfter($instance, $route, $request, $method)
Definition: compiled.php:8429
__construct($content= '', $status=200, $headers=array())
Definition: compiled.php:14210
$b
Definition: example.php:19
subMinutes($value)
Definition: compiled.php:16950
dispatchToRoute(Request $request)
Definition: compiled.php:6997
static parse($time=null, $tz=null)
Definition: compiled.php:16409
$_POST['c']
until($event, $payload=array())
Definition: compiled.php:9148
d VERSION
Definition: bootstrap.min.js:6
setupWildcardListen($event, $listener)
Definition: compiled.php:9122
timezone($value)
Definition: compiled.php:16594
setEventDispatcher(Dispatcher $dispatcher)
Definition: compiled.php:12146
extend($driver, Closure $callback)
Definition: compiled.php:11364
static only($array, $keys)
Definition: compiled.php:5536
prepareResponse($request, $response)
Definition: compiled.php:7213
static setTrustedHeaderName($key, $value)
Definition: compiled.php:2784
belongsToMany($related, $table=null, $foreignKey=null, $otherKey=null, $relation=null)
Definition: compiled.php:9614
__construct(\Iterator $iterator, array $matchPatterns, array $noMatchPatterns)
Definition: compiled.php:15348
__construct($debug=true, $charset=null, $fileLinkFormat=null)
Definition: compiled.php:4107
$loader
Definition: example.php:2
getInt($key, $default=0, $deep=false)
Definition: compiled.php:3448
extend($abstract, Closure $closure)
static firstByAttributes($attributes)
Definition: compiled.php:9492
__construct(Router $router, Container $container=null)
Definition: compiled.php:8371
addYears($value)
Definition: compiled.php:16822
abort($code, $message= '', array $headers=array())
Definition: compiled.php:1610
setRootControllerNamespace($rootNamespace)
Definition: compiled.php:8786
getWildcardListeners($eventName)
Definition: compiled.php:9192
contains($value, $checkForObjectIdentity=true, $checkForNonObjectIdentity=false)
Definition: Functions.php:1896
static create($uri, $method= 'GET', $parameters=array(), $cookies=array(), $files=array(), $server=array(), $content=null)
Definition: compiled.php:2617
Bo Bo set
Definition: d3.min.js:3
__call($method, $parameters)
Definition: compiled.php:10722
loadConfigurationFiles(Application $app, RepositoryContract $config)
Definition: compiled.php:1855
getMapperSegment($command, $segment)
Definition: compiled.php:8953
resolveClass(ReflectionParameter $parameter)
Definition: compiled.php:1069
matches($string)
Definition: Functions.php:2227
static createFromTimestampUTC($timestamp)
Definition: compiled.php:16477
render(Presenter $presenter=null)
Definition: compiled.php:5254
static quickRandom($length=16)
Definition: compiled.php:5687
getMethodDependencies($callback, $parameters=array())
Definition: compiled.php:934
emergency($message, array $context=array())
Definition: compiled.php:12378
newCollection(array $models=array())
Definition: compiled.php:9989
options($uri, $action)
Definition: compiled.php:6824
static hasTestNow()
Definition: compiled.php:16615
pattern($key, $pattern)
Definition: compiled.php:7125
setObservableEvents(array $observables)
Definition: compiled.php:9751
dispatch(Route $route, Request $request, $controller, $method)
Definition: compiled.php:8376
static toMonologLevel($level)
Definition: compiled.php:12310
replaceRoot($route, $domain, &$parameters)
Definition: compiled.php:8623
static createFromGlobals()
addMonth($value=1)
Definition: compiled.php:16842
static build($array, callable $callback)
Definition: compiled.php:5423
$_COOKIE['e']
__construct(array $messages=array())
Definition: compiled.php:13437
addNotice($message, array $context=array())
Definition: compiled.php:12275
static getTestNow()
Definition: compiled.php:16611
lastOfYear($dayOfWeek=null)
Definition: compiled.php:17211
postReset(Request $request)
Definition: compiled.php:2095
setEventDispatcher(Dispatcher $events)
Definition: Connection.php:979
addWarning($message, array $context=array())
Definition: compiled.php:12279
lists($value, $key=null)
Definition: compiled.php:11535
bind($abstract, $concrete=null, $shared=false)
Definition: compiled.php:783
Bo format
Definition: d3.min.js:3
callFilter($filter, $route, $request)
Definition: compiled.php:8468
dispatchFromArray($command, array $array)
Definition: compiled.php:8842
setContainer(Container $container)
Definition: compiled.php:7683
static lower($value)
Definition: compiled.php:5656
static random($length=16)
Definition: compiled.php:5676
gt(Carbon $dt)
Definition: compiled.php:16747
setDefaultLogger(LoggerInterface $logger, $levels=null, $replace=false)
Definition: compiled.php:5798
function e e window e e e e e e e e dev &&e dispatch e dispatch e e e render e render queue
Definition: nv.d3.min.js:1
rc rc rc years rc day
Definition: d3.min.js:3
Bo scale log
Definition: d3.min.js:4
__construct($app, ConnectionFactory $factory)
Definition: compiled.php:10621
stopSection($overwrite=false)
Definition: compiled.php:13255
addError($message, array $context=array())
Definition: compiled.php:12283
isBirthday(Carbon $dt)
Definition: compiled.php:17225
merge(array $input)
Definition: compiled.php:2330
lastOfMonth($dayOfWeek=null)
Definition: compiled.php:17176
__construct(HasherContract $hasher, $model)
Definition: compiled.php:697
diffInSeconds(Carbon $dt=null, $abs=true)
Definition: compiled.php:17034
getRouteDomain($route, &$parameters)
Definition: compiled.php:8685
static now($tz=null)
Definition: compiled.php:16413
static sort($array, callable $callback)
Definition: compiled.php:5576
static today($tz=null)
Definition: compiled.php:16417
postLogin(Request $request)
Definition: compiled.php:2027
addQueryString($uri, array $parameters)
Definition: compiled.php:8640
addAlert($message, array $context=array())
Definition: compiled.php:12291
setDispatcher(Dispatcher $events)
Definition: compiled.php:13355
$uri
Definition: server.php:9
static upper($value)
Definition: compiled.php:5692
static $translator
Definition: compiled.php:16374
glob($pattern, $flags=0)
Definition: compiled.php:6325
incrementOrDecrement($column, $amount, $method)
Definition: compiled.php:9773
clearCookie($name, $path= '/', $domain=null, $secure=false, $httpOnly=true)
Definition: compiled.php:14808
static createFromDate($year=null, $month=null, $day=null, $tz=null)
Definition: compiled.php:16452
static formatUsesPrefix($new, $old)
Definition: compiled.php:6905
__construct(UserProvider $provider, SessionInterface $session, Request $request=null)
Definition: compiled.php:392
of($view, $data=array())
Definition: compiled.php:13102
then(Closure $destination)
Definition: compiled.php:9006
mergeNewFlashes(array $keys)
Definition: compiled.php:11142
jl Io Io rc second
Definition: d3.min.js:5
addFilters($type, $filters)
Definition: compiled.php:7578
jl Io Io rc rc rc seconds rc rc rc minutes rc rc rc hours rc month
Definition: d3.min.js:5
newPivot(Model $parent, array $attributes, $table, $exists)
Definition: compiled.php:9993
ignoreEmptyContextAndExtra($ignore=true)
Definition: compiled.php:12796
static parseParameterFilter($filter)
Definition: compiled.php:7451
matches(Route $route, Request $request)
Definition: compiled.php:9086
detectEnvironment(Closure $callback)
Definition: compiled.php:1413
static where($array, callable $callback)
Definition: compiled.php:5580
a fn alert
Definition: bootstrap.min.js:6
addDefaults(array $defaults)
Definition: compiled.php:8163
static parseCallback($callback, $default)
Definition: compiled.php:5668
rc year
Definition: d3.min.js:3
setFormat($format= ':message')
Definition: compiled.php:13518
parseClassEvent($class, $prefix)
Definition: compiled.php:13221
info($message, array $context=array())
Definition: compiled.php:12063
performUpdate(Builder $query, array $options=array())
Definition: compiled.php:9833
static last($array, callable $callback, $default=null)
Definition: compiled.php:5477
toRoute($route, $parameters, $absolute)
Definition: compiled.php:8616
static resetToStringFormat()
Definition: compiled.php:16663
__construct($name, SessionHandlerInterface $handler, $id=null)
Definition: compiled.php:10968
setAction(array $action)
Definition: compiled.php:7674
Bo ya ya ya ya ya ya ya ya ya ya ya ya ya ya sort
Definition: d3.min.js:3
make($view, $data=array(), $mergeData=array())
Definition: compiled.php:13078
static getLevels()
Definition: compiled.php:12299
filter($key, $default=null, $deep=false, $filter=FILTER_DEFAULT, $options=array())
Definition: compiled.php:3456
function to(n, t)
Definition: d3.min.js:2
loadViewsFrom($path, $namespace)
Definition: compiled.php:4400
newInstance($attributes=array(), $exists=false)
Definition: compiled.php:9429
__construct(Application $app, Router $router)
Definition: compiled.php:1913
sortBy($callback, $options=SORT_REGULAR, $descending=false)
Definition: compiled.php:11628
__construct($level=Logger::DEBUG, $bubble=true)
Definition: compiled.php:12408
static plural($value, $count=2)
Definition: compiled.php:5672
server($key=null, $default=null)
Definition: compiled.php:2296
setRouteResolver(Closure $callback)
Definition: compiled.php:2422
attemptBasic(Request $request, $field)
Definition: compiled.php:495
singleton($abstract, $concrete=null)
static slug($title, $separator= '-')
Definition: compiled.php:5704
function e e window e e e e e e e e dev &&e dispatch e dispatch e e render
Definition: nv.d3.min.js:1
setProvider(UserProvider $provider)
Definition: compiled.php:639
static updated($callback, $priority=0)
Definition: compiled.php:9710
trimUrl($root, $path, $tail= '')
Definition: compiled.php:8752
__construct(EngineResolver $engines, ViewFinderInterface $finder, Dispatcher $events)
Definition: compiled.php:13065
static presenter(Closure $resolver)
Definition: compiled.php:5155
replace(array $attributes)
Definition: compiled.php:11155
alert($message, array $context=array())
Definition: compiled.php:12043
addEventListener($name, $callback, $priority=null)
Definition: compiled.php:13205
callFilter($filter, $request, $response=null)
Definition: compiled.php:7135
offsetSet($key, $value)
Definition: compiled.php:13681
getContent(FlattenException $exception)
Definition: compiled.php:4200
fire($event, $payload=array(), $halt=false)
Definition: compiled.php:9160
matches(Route $route, Request $request)
Definition: compiled.php:9070
Bo Bo map
Definition: d3.min.js:3
static __callStatic($method, $args)
Definition: compiled.php:5353
getNumericParameters(array $parameters)
Definition: compiled.php:8679
setDefaults(array $defaults)
Definition: compiled.php:8158
subSecond($value=1)
Definition: compiled.php:16962
newRoute($methods, $uri, $action)
Definition: compiled.php:6945
diffInDaysFiltered(Closure $callback, Carbon $dt=null, $abs=true)
Definition: compiled.php:16989
static setTestNow(Carbon $testNow=null)
Definition: compiled.php:16607
startSection($section, $content= '')
Definition: compiled.php:13237
call($callback, array $parameters=array(), $defaultMethod=null)
refresh($abstract, $target, $method)
Definition: compiled.php:893
toJson($data, $ignoreErrors=false)
Definition: compiled.php:12753
static all($columns=array('*'))
Definition: compiled.php:9511
matches(Route $route, Request $request)
Definition: compiled.php:9059
__set($name, $value)
Definition: compiled.php:16523
migrate($destroy=false, $lifetime=null)
Definition: compiled.php:11042
static flatten($array)
Definition: compiled.php:5481
callPatternFilters($route, $request)
Definition: compiled.php:7144
morphToMany($related, $name, $table=null, $foreignKey=null, $otherKey=null, $inverse=false)
Definition: compiled.php:9628
static $timezone
Definition: compiled.php:12192
critical($message, array $context=array())
Definition: compiled.php:12366
mapUsing(Closure $mapper)
Definition: compiled.php:8961
Bo Bo timer flush
Definition: d3.min.js:3
bootstrapWith(array $bootstrappers)
Definition: compiled.php:1309
to($path, $extra=array(), $secure=null)
Definition: compiled.php:8562
subYears($value)
Definition: compiled.php:16834
__call($method, $parameters)
Definition: compiled.php:5398
first(callable $callback=null, $default=null)
Definition: compiled.php:11455
render(Closure $callback=null)
Definition: compiled.php:13587
__construct(Dispatcher $events, Container $container=null)
Definition: compiled.php:6798
average(Carbon $dt=null)
Definition: compiled.php:17220
static created($callback, $priority=0)
Definition: compiled.php:9718
extendSection($section, $content)
Definition: compiled.php:13275
Bo Bo Bo max
Definition: d3.min.js:3
replaceDefaults(array $parameters)
Definition: compiled.php:7541
previous($dayOfWeek=null)
Definition: compiled.php:17161
regenerate($destroy=false)
Definition: compiled.php:11051
validRecaller($recaller)
Definition: compiled.php:459
traceAt($levels, $replace=false)
Definition: compiled.php:5874
buildContentFiltering(Command $command, array $contains, $not=false)
Definition: compiled.php:16030
pull($key, $default=null)
Definition: compiled.php:11563
setUser(UserContract $user)
Definition: compiled.php:647
Or prototype prepare
Definition: d3.min.js:4
afterFilter($filter, array $options=array())
Definition: compiled.php:8276
composer($views, $callback, $priority=null)
Definition: compiled.php:13180
useErrorLog($level= 'debug', $messageType=ErrorLogHandler::OPERATING_SYSTEM)
Definition: compiled.php:12098
$hash
validate(array $credentials=array())
Definition: compiled.php:475
nthOfMonth($nth, $dayOfWeek)
Definition: compiled.php:17184
wrap(Closure $callback, array $parameters=array())
Definition: compiled.php:913
findCallable(array $action)
Definition: compiled.php:7557
max(Carbon $dt=null)
Definition: compiled.php:16781
callRouteFilter($filter, $parameters, $route, $request, $response=null)
Definition: compiled.php:7202
file($path, $data=array(), $mergeData=array())
Definition: compiled.php:13072
setQueueResolver(callable $resolver)
Definition: compiled.php:9281
Bo geo Bo geo transform
Definition: d3.min.js:4
__call($method, $parameters)
Definition: compiled.php:10588
static maxValue()
Definition: compiled.php:16429
subMinute($value=1)
Definition: compiled.php:16946
static create(array $attributes)
Definition: compiled.php:9456
file($key=null, $default=null)
Definition: compiled.php:2272
print $version
$a
Definition: example.php:18
belongsTo($related, $foreignKey=null, $otherKey=null, $relation=null)
Definition: compiled.php:9564
addHour($value=1)
Definition: compiled.php:16926
input($key=null, $default=null)
Definition: compiled.php:2238
implode($value, $glue=null)
Definition: compiled.php:11507
boot(DispatcherContract $events)
Definition: compiled.php:17276
publishes(array $paths, $group=null)
Definition: compiled.php:4411
prepare(Connection $connection)
Definition: compiled.php:10677
min(Carbon $dt=null)
Definition: compiled.php:16776
nthOfYear($nth, $dayOfWeek)
Definition: compiled.php:17215
eq(Carbon $dt)
Definition: compiled.php:16739
createQueuedHandlerCallable($class, $method)
Definition: compiled.php:9243
__construct(CompilerInterface $compiler)
Definition: compiled.php:13760
bootProvider(ServiceProvider $provider)
Definition: compiled.php:1523
$response
Definition: index.php:51
callAttachedBefores($route, $request)
Definition: compiled.php:7187
pipeThrough(array $pipes)
Definition: compiled.php:8970
__construct(array $items=array())
Definition: compiled.php:6129
newFromBuilder($attributes=array(), $connection=null)
Definition: compiled.php:9435
put($key, MessageBagContract $bag)
Definition: compiled.php:13403
__call($method, $parameters)
Definition: compiled.php:11373
isSameDay(Carbon $dt)
Definition: compiled.php:16818
dispatch(Request $request)
Definition: compiled.php:6986
getRouteQueryString(array $parameters)
Definition: compiled.php:8662
runWithCustomDispatcher(Request $request)
Definition: compiled.php:7375
share($key, $value=null)
Definition: compiled.php:13155
Bo ya ya ya ya ya ya ya ya ya ya data
Definition: d3.min.js:3
setFormatter(FormatterInterface $formatter)
Definition: compiled.php:12441
addMonthNoOverflow($value=1)
Definition: compiled.php:16862
creator($views, $callback)
Definition: compiled.php:13164
static parseFilter($filter)
Definition: compiled.php:7444
route($method, $name, $routeParameters=[], $parameters=[], $cookies=[], $files=[], $server=[], $content=null)
detectConsoleEnvironment(Closure $callback, array $args)
Definition: compiled.php:1681
search($value, $strict=false)
Definition: compiled.php:11598
getCallbacksForType($abstract, $object, array $callbacksPerType)
Definition: compiled.php:1143
mergeReadWriteConfig(array $config, array $merge)
Definition: compiled.php:10791
registerBag(SessionBagInterface $bag)
Definition: compiled.php:11182
whenRegex($pattern, $name, $methods=null)
Definition: compiled.php:7087
parseWhere($name, $expression)
Definition: compiled.php:7601
replaceRouteParameters($path, array &$parameters)
Definition: compiled.php:8627
diffInMonths(Carbon $dt=null, $abs=true)
Definition: compiled.php:16975
$filter
Definition: auto_prepend.php:5
setContainer(Container $container)
Definition: compiled.php:13363
setParameter($name, $value)
Definition: compiled.php:7468
setContentTags($openTag, $closeTag, $escaped=false)
Definition: compiled.php:14112
hour($value)
Definition: compiled.php:16570
addWeek($value=1)
Definition: compiled.php:16910
formatDomain($route, &$parameters)
Definition: compiled.php:8689
setRequirements(array $requirements)
Definition: compiled.php:8189
__construct($value, array $attributes=array())
Definition: compiled.php:3939
__construct(Filesystem $files, array $paths, array $extensions=null)
Definition: compiled.php:12943
static pull(&$array, $key, $default=null)
Definition: compiled.php:5554
static forceCreate(array $attributes)
Definition: compiled.php:9462
static make($items=null)
Definition: compiled.php:11397
subWeekdays($value)
Definition: compiled.php:16902
resolvingCallback(Closure $callback)
Definition: compiled.php:1106
__construct($methods, $uri, $action)
Definition: compiled.php:7330
getCachingIterator($flags=CachingIterator::CALL_TOSTRING)
Definition: compiled.php:11708
Bo ya ya ya ya ya ya ya append
Definition: d3.min.js:3
configureErrorlogHandler(Application $app, Writer $log)
Definition: compiled.php:1731
__call($method, $parameters)
Definition: compiled.php:4463
Bo geo stream
Definition: d3.min.js:3
loginUsingId($id, $remember=false)
Definition: compiled.php:561
lte(Carbon $dt)
Definition: compiled.php:16759
addRoute($methods, $uri, $action)
Definition: compiled.php:6929
bindParameters(Request $request)
Definition: compiled.php:7513
static create($year=null, $month=null, $day=null, $hour=null, $minute=null, $second=null, $tz=null)
Definition: compiled.php:16437
subMonth($value=1)
Definition: compiled.php:16846
$tag
where($key, $value, $strict=true)
Definition: compiled.php:11445
static parseFilters($filters)
Definition: compiled.php:7423
map(callable $callback)
Definition: compiled.php:11539
performInsert(Builder $query, array $options=array())
Definition: compiled.php:9851
getBasicCredentials(Request $request, $field)
Definition: compiled.php:502
static hasRelativeKeywords($time)
Definition: compiled.php:16619
addNamespace($namespace, $hints)
Definition: compiled.php:13318
static resolveConnection($connection=null)
Definition: compiled.php:10507
Bo ya ya ya ya ya ya ya ya ya ya ya ya ya ya ya ya ya empty
Definition: d3.min.js:3
hasValidCredentials($user, $credentials)
Definition: compiled.php:523
setRoutes(RouteCollection $routes)
Definition: compiled.php:7290
callComposer(View $view)
Definition: compiled.php:13229
getStylesheet(FlattenException $exception)
Definition: compiled.php:4250
flash($filter=null, $keys=array())
Definition: compiled.php:2304
getFunctionHint(Closure $callback)
Definition: compiled.php:1124
pushHandler(HandlerInterface $handler)
Definition: compiled.php:12206
callRouteAfter($route, $request, $response)
Definition: compiled.php:7196
loadTranslationsFrom($path, $namespace)
Definition: compiled.php:4407
warning($message, array $context=array())
Definition: compiled.php:12350
$basePath
Definition: config.php:3
diffFiltered(CarbonInterval $ci, Closure $callback, Carbon $dt=null, $abs=true)
Definition: compiled.php:16997
prependNamespace($namespace, $hints)
Definition: compiled.php:13006
jl Io Io rc rc rc seconds rc rc rc minutes rc hour
Definition: d3.min.js:5
retrieveItem($source, $key, $default)
Definition: compiled.php:2323
function name
Definition: holder.js:1522
notice($message, array $context=array())
Definition: compiled.php:12059
flashInput(array $value)
Definition: compiled.php:11127
__construct($items, $perPage, $currentPage=null, array $options=array())
Definition: compiled.php:5223
addMonthsNoOverflow($value)
Definition: compiled.php:16854
bindPathParameters(Request $request)
Definition: compiled.php:7521
listen(Closure $callback)
Definition: compiled.php:12103
actionReferencesController($action)
Definition: compiled.php:6963
__construct($path, array $defaults=array(), array $requirements=array(), array $options=array(), $host= '', $schemes=array(), $methods=array(), $condition= '')
Definition: compiled.php:8025